source: project/wiki/eggref/5/shen @ 37187

Last change on this file since 37187 was 37187, checked in by svnwiki, 4 months ago

Anonymous wiki edit for IP [220.233.44.123]:

File size: 4.4 KB
Line 
1== shen
2
3A port of the [[http://www.shenlanguage.org/|Shen programming language]] for Chicken Scheme.
4
5[[toc:]]
6
7=== Shen
8
9[[http://www.shenlanguage.org/|Shen]] is a hosted language that comes with a macro system, optional type system based on [[https://en.wikipedia.org/wiki/Sequent_calculus|sequent calculus]], pattern matching, [[https://en.wikipedia.org/wiki/Lambda_calculus|λ calculus]] consistency, optional lazy evaluation, an integrated prolog and compiler-compiler.
10
11This egg comes with a standalone binary chicken-shen that provides a REPL and a shen library to use Shen inside Scheme.
12
13=== Egg Author
14
15David Ireland (djireland79 at gmail dot com)
16
17=== Shen Documentation
18
19The best source of information for Shen programming is the
20[[https://www.amazon.com/Book-Shen-third-Mark-Tarver/dp/1784562130/ref=sr_1_1?ie=UTF8&qid=1548832486&sr=8-1&keywords=the+book+of+shen| The Book of Shen]] and the [[http://www.shenlanguage.org/|Shen web site]]
21.
22=== Egg Source Code
23
24[[https://code.sarnath.xyz/chicken-shen |Chicken-Shen]]
25
26=== Chicken Shen Usage
27
28Usage for the standalone binary for running a REPL or loading a file or string is here:
29<enscript highlight="bash">
30$ chicken-shen -h
31</enscript>
32
33<enscript highlight="bash"> 
34Usage: shen [options] [...args...]
35  -h, --help          : Prints help and exits
36  -l, --load <file>   : Loads Shen <file>
37  -e, --eval <string> : Evaluates <string>
38  -r, --repl          : Run the REPL, even if -l or -e are provided
39Any additional arguments are passed to the Shen system in
40the variable shen-chicken.*argv*
41</enscript>
42
43==== Starting the REPL from a terminal
44
45<enscript highlight="bash">
46$ chicken-shen -r
47</enscript>
48
49<enscript highlight="bash">
50Shen, copyright (C) 2010-2015 Mark Tarver
51www.shenlanguage.org, Shen 21.1
52running under Scheme, implementation: Chicken
53port 0.1 ported by David Ireland
54
55(0-)
56</enscript>
57
58=== Calling Shen from Scheme
59
60<procedure> (run-shen) </procedure>
61Runs the REPL inside Chicken Scheme
62
63<procedure> (read-file FILE) </procedure>
64Reads and loads a shen file
65
66<procedure> (read-from-string STRING) </procedure>
67Reads and loads a string containing Shen code.
68
69<enscript highlight="lisp">
70 (import (prefix shen shen:))
71 
72 ;;; Load file example
73 (shen:read-file "foo.shen")
74
75 ;;; Evaluate string
76 (shen:read-from-string "(define foo 0 -> 1 1 -> 0)")
77 (shen:read-from-string "(foo 0)") ;;; Should return 1
78 
79</enscript>
80
81=== Example Shen Code
82
83==== Symbols
84
85Unlike Chicken Scheme symbols are implicitly quoted thus no ' is needed.
86<enscript highlight="lisp">
87(0-) HI
88HI
89</enscript>
90
91==== Basic List processing
92
93Lists in Shen are enclosed with [ ] for example:
94
95<enscript highlight="lisp">
96(12-) [1 2 3]
97(13-) (head [1 2 3])
981
99(14-) (cons 1 [])
100[1]
101(15-) [1 2 | [3]]
102[1 2 3]
103</enscript>
104
105==== Procedures
106
107Procedures are defined using a pattern matching. For example:
108<enscript highlight="lisp">
109(define factorial
110        0 -> 1
111        X -> (* X (factorial (- X 1))))
112</enscript>
113
114<enscript highlight="lisp">
115(define total
116        [] -> 0
117        [X | Y] -> (+ X (total Y)))
118</enscript>
119
120
121<enscript highlight="lisp">
122(define triples
123        [] -> []
124        [W X Y | Z] -> [[W X Y] | (triples Z)])
125</enscript>
126
127==== YACC
128Shen has an internal YACC (yet another compiler compiler)
129
130<enscript highlight="lisp">
131(defcc <binary?>
132X <binary?> := true where (element? X [0 1]);
133X := true where (element? X [0 1]);
134<e> := false;)
135</enscript>
136
137==== Prolog
138
139Shen also has an embedded prolog for logic programming
140
141<enscript highlight="lisp">
142(defprolog member
143xxX [X | _] <--;
144xxX [_ | Y] <-- (member X Y);)
145</enscript>
146
147==== Type System
148
149The type system is optional and disabled by default. It can be enabled using:
150<enscript highlight="lisp"> 
151(0-) (tc +)
152true
153
154(1+) 5
1555 : number
156
157(2+) "ABC"
158"ABC" : string
159
160(3+) (+ 1 1)
1612 : number
162</enscript>
163
164and off with:
165
166<enscript highlight="lisp"> 
167(4+) (tc -)
168false : boolean
169
170(5-) 5
1715
172
173(6-) "ABC"
174"ABC"
175
176(7-) (+ 1 1)
1772
178</enscript>
179
180
181==== Calling native Scheme code from Shen
182
183Calling native Chicken procedures is done by prefixing 'lisp' to the procedure name. An example of calling Chicken's print is given below.
184
185<enscript highlight="bash">
186Shen, copyright (C) 2010-2015 Mark Tarver
187www.shenlanguage.org, Shen 21.1
188running under Scheme, implementation: Chicken
189port 0.1 ported by David Ireland
190
191(0-) (lisp.print "Hello World")
192Hello World
193#<unspecified>
194
195(1-)
196</enscript>
197
198
199=== About this egg
200
201==== License
202BSD Clause 3
203
204==== Dependencies
205srfi-1
206srfi-13
207
208==== Versions
209
Note: See TracBrowser for help on using the repository browser.