Commit 14000c0a authored by Chris Müller's avatar Chris Müller
Browse files

Add introductionary cherry file

parent 9f9d82b3
;; Booleans
(let yes true)
(let no false)
;; Numbers
(let hex 0xFF)
(let oct 0777)
(let bin 0b1111)
(let dez 10)
;; Characters
(let space \space)
(let newline \newline)
(let A \A)
(let tab \tab)
;; Strings and Raw-Strings
(let string "teststring\n")
(let rawstring ~[a-zA-Z]+@[a-zA-Z]+\.de~)
;; Pair definition
(define (complex real imag)
(cons real imag))
;; List defintion
(define (point x y z)
(let with-cons (cons x (cons y (cons z '()))))
(let with-list (list x y z))
with-list)
;; Tuple definition (vectors)
(define (pointd x y z)
(tuple x y z))
;; Function definitions
(define (function a b)
(println a " --- " b))
;; Lambda expressions (anonymous function
(define (bla a)
(let smaller (lambda (b) (< a b)))
(smaller 10))
;; if statements (supported operators: and, or, not, <, >, >=, =<, =)
(define (max a b)
(if (or (and (1 > a) (2 < b))
(not false) true)
(println "True")
(if (= a b)
(println "a = b")
(pritnln "a != b"))))
;; named let / recursive looping
(define (range from to)
(loop (add (x from) (xs '()))
(if (< x to)
(add (+ x 1) (cons x xs))
(cons (+ x 1) xs))))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment