Pārlūkot izejas kodu

Add readme and base stuff

Lily Carpenter 8 gadi atpakaļ
revīzija
0d6c50b105
5 mainītis faili ar 239 papildinājumiem un 0 dzēšanām
  1. 70 0
      .gitignore
  2. 8 0
      README.org
  3. 19 0
      quickstart/messenger-back.lfe
  4. 15 0
      quickstart/sample-module.lfe
  5. 127 0
      spels/game.lfe

+ 70 - 0
.gitignore

@@ -0,0 +1,70 @@
1
+# Created by https://www.gitignore.io/api/emacs,linux,erlang
2
+
3
+### Emacs ###
4
+# -*- mode: gitignore; -*-
5
+*~
6
+\#*\#
7
+/.emacs.desktop
8
+/.emacs.desktop.lock
9
+*.elc
10
+auto-save-list
11
+tramp
12
+.\#*
13
+
14
+# Org-mode
15
+.org-id-locations
16
+*_archive
17
+
18
+# flymake-mode
19
+*_flymake.*
20
+
21
+# eshell files
22
+/eshell/history
23
+/eshell/lastdir
24
+
25
+# elpa packages
26
+/elpa/
27
+
28
+# reftex files
29
+*.rel
30
+
31
+# AUCTeX auto folder
32
+/auto/
33
+
34
+# cask packages
35
+.cask/
36
+dist/
37
+
38
+# Flycheck
39
+flycheck_*.el
40
+
41
+# server auth directory
42
+/server/
43
+
44
+# projectiles files
45
+.projectile
46
+
47
+### Linux ###
48
+*~
49
+
50
+# temporary files which can be created if a process still has a handle open of a deleted file
51
+.fuse_hidden*
52
+
53
+# KDE directory preferences
54
+.directory
55
+
56
+# Linux trash folder which might appear on any partition or disk
57
+.Trash-*
58
+
59
+
60
+### Erlang ###
61
+.eunit
62
+deps
63
+*.o
64
+*.beam
65
+*.plt
66
+erl_crash.dump
67
+ebin
68
+rel/example_project
69
+.concrete/DEV_MODE
70
+.rebar

+ 8 - 0
README.org

@@ -0,0 +1,8 @@
1
+* Lisp Flavored Erlang Presentation
2
+
3
+This is some code to present at Arch Lisp to show off Lisp Flavored Erlang.
4
+
5
+Currently the code is derived from:
6
+
7
+- [[https://lfe.gitbooks.io/quick-start/content/]]
8
+- [[https://www.gitbook.com/book/lfe/casting-spels/details]]

+ 19 - 0
quickstart/messenger-back.lfe

@@ -0,0 +1,19 @@
1
+(defmodule messenger-back
2
+  (export (print-result 0)
3
+          (send-message 2)))
4
+
5
+(defun print-result ()
6
+  (receive
7
+    (`#(,pid ,msg)
8
+     (io:format "Received message: '~s'~n" (list msg))
9
+     (io:format "Sending message to process ~p ...~n" (list pid))
10
+     (! pid `#(,msg))
11
+     (print-result))))
12
+
13
+(defun send-message (calling-pid msg)
14
+  (let ((spawned-pid (spawn 'messenger-back 'print-result '())))
15
+    (! spawned-pid (tuple calling-pid msg))))
16
+
17
+(defun demo ()
18
+  (messenger-back:send-message (self) "And what does it say now?")
19
+  (messenger-back:send-message (self) "Mostly harmless."))

+ 15 - 0
quickstart/sample-module.lfe

@@ -0,0 +1,15 @@
1
+(defmodule sample-module
2
+  (export all))
3
+
4
+(defun my-sum (start stop)
5
+  (let ((my-list (lists:seq start stop)))
6
+    (* 2 (lists:foldl
7
+          (lambda (n acc)
8
+            (+ n acc))
9
+          0 my-list))))
10
+
11
+(defun demo ()
12
+  (io:format "2 * (6 + 5 + 4 + 3 + 2 + 1) = ~p~n" (list (sample-module:my-sum 1 6)))
13
+  (io:format "2 * (60 + 59 + ...) = ~p~n" (list (sample-module:my-sum 1 60)))
14
+  (io:format "2 * (600 + 599 + ...) = ~p~n" (list (sample-module:my-sum 1 600)))
15
+  (io:format "2 * (6000 + 5999 + ...) = ~p~n" (list (sample-module:my-sum 1 6000))))

+ 127 - 0
spels/game.lfe

@@ -0,0 +1,127 @@
1
+(defmodule game
2
+  (export all))
3
+
4
+;; Creates:
5
+;; make-exit
6
+;; exit-direction
7
+;; exit-object
8
+;; exit-destination
9
+;; set-exit
10
+;; set-exit-direction
11
+;; set-exit-object
12
+;; set-exit-destination
13
+;; match-exit
14
+;; ...
15
+(defrecord exit
16
+  direction
17
+  object
18
+  destination)
19
+
20
+(defrecord place
21
+  name
22
+  description
23
+  exits)
24
+
25
+(defrecord object
26
+  name
27
+  location)
28
+
29
+(defrecord goal
30
+  name
31
+  achieved?)
32
+
33
+(defrecord state
34
+  objects
35
+  places
36
+  player-location
37
+  goals)
38
+
39
+(set objects
40
+     (list (make-object name 'whiskey-bottle location 'living-room)
41
+           (make-object name 'bucket location 'living-room)
42
+           (make-object name 'frog location 'garden)
43
+           (make-object name 'chain location 'garden)))
44
+
45
+(set living-room
46
+     (make-place
47
+      name 'living-room
48
+      description (++ "You are in the living-room of a wizard's house. "
49
+                      "There is a wizard snoring loudly on the couch.")
50
+      exits (list
51
+             (make-exit
52
+              direction "west"
53
+              object "door"
54
+              destination 'garden)
55
+             (make-exit
56
+              direction "upstairs"
57
+              object "stairway"
58
+              destination 'attic))))
59
+
60
+(set garden
61
+     (make-place
62
+      name 'garden
63
+      description (++ "You are in a beautiful garden. "
64
+                      "There is a well in front of you.")
65
+      exits (list
66
+             (make-exit
67
+              direction "east"
68
+              object "door"
69
+              destination 'living-room))))
70
+
71
+(set attic
72
+     (make-place
73
+      name 'attic
74
+      description (++ "You are in the attic of the wizard's house. "
75
+                      "There is a giant welding torch in the corner.")
76
+      exits (list
77
+             (make-exit
78
+              direction "downstairs"
79
+              object "stairway"
80
+              destination 'living-room))))
81
+
82
+(set netherworld
83
+     (make-place
84
+      name 'netherworld
85
+      description (++ "Everything is misty and vague. "
86
+                      "You seem to be in the netherworld.\n"
87
+                      "There are no exits.\n"
88
+                      "You could be here for a long, long time ...")
89
+      exits '()))
90
+
91
+(set goals
92
+     (list (make-goal name 'weld-chain achieved? 'false)
93
+           (make-goal name 'dunk-bucket achieved? 'false)
94
+           (make-goal name 'splash-wizard achieved? 'false)))
95
+
96
+(set state (make-state
97
+               objects objects
98
+               places (list living-room garden attic netherworld)
99
+               player-location 'living-room
100
+               goals goals))
101
+
102
+(defun here?
103
+  ((loc (match-place name place-name)) (when (== loc place-name))
104
+   'true)
105
+  ((_ _)
106
+   'false))
107
+
108
+(defun get-here
109
+  (((match-state player-location player-loc places locs))
110
+   (car (lists:filter
111
+         (lambda (loc)
112
+           (here? player-loc loc))
113
+         locs))))
114
+
115
+(defun describe-location (game-state)
116
+  (++ (place-description (get-here game-state)) "\n"))
117
+
118
+(defun describe-exit
119
+  (((match-exit object obj direction dir))
120
+   (++ "There is a " obj " going " dir " from here.")))
121
+
122
+(defun describe-exits (game-state)
123
+  (string:join
124
+    (lists:map
125
+      #'describe-exit/1
126
+      (place-exits (get-here game-state)))
127
+    " "))