Differences From
Artifact [58b3a515c7]:
14 14 ; (@ … ) introduces a block of Scheme code that
15 15 ; is evaluated in the program's environment, but
16 16 ; whose value is silently ignored. this makes it
17 17 ; good for defining globals you intend to use
18 18 ; later in the program with (* … ) or (= … )
19 19 ; blocks - see the paragraph below
20 20 (define (sayl str)
21 - `(add-> total (call write 1
21 + `(add-> total (call write 1
22 22 ; the return value of a scheme expression will
23 23 ; be evaluated just like any other expression
24 24 ; and transformed into C code, so we can rely
25 25 ; on existing syntax instead of haven't to
26 26 ; generate raw strings of C
27 27 ,(string-append str "\\n")
28 28 ,(+ 1 (string-length str))))))
29 29
30 30 (decl sayhello ((ptr char) → int))
31 +(decl usage (() => ()))
31 32 (def (total size_t) 0)
32 33
33 34 (def (main int (argc int) (argv (array (ptr char))))
34 - (ret (call sayhello "dumbass")))
35 + (def (voidptr (ptr ())) (cast (ptr ()) argv))
36 + (cond ((neq argc 2) (call usage))
37 + (else (call sayhello (idx argv 1)))))
35 38
36 39 (def (sayhello int (name (ptr char)))
37 40 (* sayl "hello…")
38 41 ; a list prefixed with * indicates that it
39 42 ; should be evaluated as a scheme expression
40 43 ; and its result then processed, instead of
41 44 ; being processed directly like (call) or
................................................................................
42 45 ; (def). scheme expressions may be inserted
43 46 ; anywhere a normal sexpc expression can. or
44 47 ; we could instead write (= (sayl "hello…"))
45 48 ; to accomplish the same effect; (= … ) is
46 49 ; really just shorthand for (* begin … )
47 50
48 51 (call write 1 name (call strlen name))
49 - (ret total)
50 -)
52 + (ret total))
53 +
54 +(def (usage void ())
55 + (* sayl "usage: example <name>"))
56 +