Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
8
Task/Enumerations/Scheme/enumerations-1.ss
Normal file
8
Task/Enumerations/Scheme/enumerations-1.ss
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(define apple 0)
|
||||
(define banana 1)
|
||||
(define cherry 2)
|
||||
|
||||
(define (fruit? atom)
|
||||
(or (equal? 'apple atom)
|
||||
(equal? 'banana atom)
|
||||
(equal? 'cherry atom)))
|
||||
40
Task/Enumerations/Scheme/enumerations-2.ss
Normal file
40
Task/Enumerations/Scheme/enumerations-2.ss
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
; Syntax that implements a C-like enum; items without assignment take next value.
|
||||
; Form: (enum <name> <item>...)
|
||||
; Where <name> is a symbol that will be the name of the enum; <item> are one or
|
||||
; more expressions that are either symbols or lists of symbol and integer value.
|
||||
; The symbols are bound to the values. If a value is not given, then the next
|
||||
; integer after the one bound to the previous symbol is used (starting at 0).
|
||||
; The <name> itself is bound to an a-list of the item symbols and their values.
|
||||
|
||||
(define-syntax enum
|
||||
(lambda (x)
|
||||
(syntax-case x ()
|
||||
((_ name itm1 itm2 ...)
|
||||
(identifier? (syntax name))
|
||||
(syntax
|
||||
(begin
|
||||
(define name '())
|
||||
(enum-help name 0 itm1 itm2 ...)))))))
|
||||
|
||||
; Helper for (enum) syntax, above. Do not call directly!
|
||||
|
||||
(define-syntax enum-help
|
||||
(lambda (x)
|
||||
(syntax-case x ()
|
||||
((_ name nxint)
|
||||
(syntax (void)))
|
||||
((_ name nxint (sym val) rest ...)
|
||||
(and (identifier? (syntax sym))
|
||||
(integer? (syntax-object->datum (syntax val))))
|
||||
(syntax
|
||||
(begin
|
||||
(define sym val)
|
||||
(set! name (cons (cons 'sym val) name))
|
||||
(enum-help name (1+ val) rest ...))))
|
||||
((_ name nxint sym rest ...)
|
||||
(identifier? (syntax sym))
|
||||
(syntax
|
||||
(begin
|
||||
(define sym nxint)
|
||||
(set! name (cons (cons 'sym nxint) name))
|
||||
(enum-help name (1+ nxint) rest ...)))))))
|
||||
28
Task/Enumerations/Scheme/enumerations-3.ss
Normal file
28
Task/Enumerations/Scheme/enumerations-3.ss
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
(define-syntax test
|
||||
(syntax-rules ()
|
||||
((_ e)
|
||||
(printf "~a --> ~s~%" 'e e))))
|
||||
|
||||
(printf "~%The 'foo' enum:~%")
|
||||
|
||||
(enum foo a (b 10) c (d 20) e (f 30) g)
|
||||
|
||||
(test a)
|
||||
(test b)
|
||||
(test c)
|
||||
(test d)
|
||||
(test e)
|
||||
(test f)
|
||||
(test g)
|
||||
(test foo)
|
||||
(test (assq 'd foo))
|
||||
(test (assq 'm foo))
|
||||
|
||||
(printf "~%The 'bar' enum:~%")
|
||||
|
||||
(enum bar x y (z 99))
|
||||
|
||||
(test x)
|
||||
(test y)
|
||||
(test z)
|
||||
(test bar)
|
||||
Loading…
Add table
Add a link
Reference in a new issue