Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ want to help make Klister a more practical language, please `reach out`_!
Here are the most prominent Racket features which are missing from Klister:

* Klister does not yet support custom readers, and thus every ``#lang`` looks like a
Lisp. This also limits languages to Integer literals and String literals.
Lisp. This also limits languages to Integer literals, builtin fixnums and String literals.
* `local-expand`_ is planned, but not yet implemented.
* `Syntax parameters`_ are planned, but not yet implemented.

Expand Down
2 changes: 1 addition & 1 deletion examples/anaphoric-if.kl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
,else])))))

(example
(if-non-empty (snoc (list 1 2 3) 4)
(if-non-empty (snoc (list (the Integer 1) 2 3) 4)
(:: 0 it)
(list 0)))
7 changes: 3 additions & 4 deletions examples/datatype-macro.kl
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
[(cons x xs)
(pure (quasiquote/loc more (:: ,x ,(cons-list-syntax 'list xs xs))))])]))]))

(example (reverse (:: 1 (:: 2 (:: 3 (nil))))))
(example (reverse (:: (the Integer 1) (:: 2 (:: 3 (nil))))))

(example (reverse (list 1 2 3)))
(example (reverse (list (the Integer 1) 2 3)))

(define-macros
([null (lambda (stx) (pure '(nil)))]))
Expand All @@ -48,5 +48,4 @@

(example (case (reverse null) [null 'a]))

(example (case (reverse (list 1 2 3)) [(head x) x]))

(example (case (reverse (list (the Integer 1) 2 3)) [(head x) x]))
8 changes: 4 additions & 4 deletions examples/define-syntax-rule-test.kl
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
(define-macro (lambda2a x y body)
(pure `(lambda (,x ,y) ,body)))
(define mk-pair-a (lambda2a x y (pair x y)))
(example (mk-pair-a 1 2))
(example (mk-pair-a (the Integer 1) (the Integer 2)))

(define-variadic-macro (lambda2b stx)
(case (open-syntax stx)
[(list-contents (list _ x y body))
(pure `(lambda (,x ,y) ,body))]))
(define mk-pair-b (lambda2b x y (pair x y)))
(example (mk-pair-b 1 2))
(example (mk-pair-b (the Integer 1) (the Integer 2)))

(define-syntax-rule (lambda2c x y body)
(lambda (x y) body))
(lambda (x y) body))
(define mk-pair-c (lambda2c x y (pair x y)))
(example (mk-pair-c 1 2))
(example (mk-pair-c (the Integer 1) (the Integer 2)))
6 changes: 3 additions & 3 deletions examples/either-datatype.kl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
(example (run-either integer->string id))

-- "42"
(example (run-either integer->string id (left 42)))
(example (run-either integer->string id (left (the Integer 42))))


-- Next, let's define a variant of Either with three cases: leftmost, center,
Expand Down Expand Up @@ -115,10 +115,10 @@
(pure `(:: ,x (nil)))]))))

-- (:: 42 (nil))
(example (head 42))
(example (head (the Integer 42)))

-- 1
(example (case (list 1 2 3)
(example (case (list (the Integer 1) 2 3)
[(head x)
x]))

Expand Down
22 changes: 11 additions & 11 deletions examples/eta-case.kl
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
[(:: x xs)
(pair x xs)]
[(nil)
(pair 0 (nil))]))
(pair (the Integer 0) (nil))]))

(example (list-to-pair (list)))
-- =>
-- (pair 0 (nil))

(example (list-to-pair (list 1 2 3)))
(example (list-to-pair (list (the Integer 1) 2 3)))
-- =>
-- (pair 1 (list 2 3))

Expand Down Expand Up @@ -332,11 +332,11 @@
-- =>
-- (lambda (x xs) (:: x xs))

(example (cons-lambda 1))
(example (cons-lambda (the Integer 1)))
-- =>
-- (lambda (xs) (:: 1 xs))

(example (cons-lambda 1 (list 2 3)))
(example (cons-lambda (the Integer 1) (list 2 3)))
-- =>
-- (list 1 2 3)

Expand Down Expand Up @@ -381,40 +381,40 @@
-- =>
-- (lambda (x xs) (:: x xs))

(example (cons 1))
(example (cons (the Integer 1)))
-- =>
-- (lambda (xs) (:: 1 xs))

(example (cons 1 (list 2 3)))
(example (cons (the Integer 1) (list 2 3)))
-- =>
-- (list 1 2 3)

(example
(case (list 1 2 3)
(case (list (the Integer 1) 2 3)
[(cons x xs)
(pair x xs)]))
-- =>
-- (pair 1 (list 2 3))

-- All right, we can finally test eta-case and eta-case-aux!
(example
((eta-case-aux (list 1 2 3)
((eta-case-aux (list (the Integer 1) 2 3)
(cons)
(pair)
[(nil) (pair 0 (nil))])
[(nil) (pair (the Integer 0) (nil))])
(cons)))
-- =>
-- (pair 1 (list 2 3))

(defun eta-list-to-pair (xs0)
(eta-case xs0
[(cons) (pair)]
[(nil) (pair 0 (nil))]))
[(nil) (pair (the Integer 0) (nil))]))

(example (eta-list-to-pair (list)))
-- =>
-- (pair 0 (nil))

(example (eta-list-to-pair (list 1 2 3)))
(example (eta-list-to-pair (list (the Integer 1) 2 3)))
-- =>
-- (pair 1 (list 2 3))
14 changes: 14 additions & 0 deletions examples/fixnum.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
12 : Integer
255 : Word64
26 : Word32
22 : Word16
12 : Word8
12 : Int64
12 : Int32
12 : Int16
0 : Int8
8 : Int32
92 : Int8
-8 : Int8
25 : Integer
129 : Integer
17 changes: 17 additions & 0 deletions examples/fixnum.kl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#lang "prelude.kl"


(example (the Integer 0b1100)) -- 12
(example (the Word64 0xFF)) -- 255
(example (the Word32 0o32)) -- 26
(example (the Word16 22))
(example (the Word8 12))
(example (the Int64 12))
(example (the Int32 12))
(example (the Int16 12))
(example (the Int8 256)) -- note no bounds checking with the primitives this is 0
(example (int32-popcount 0xFF)) -- 8
(example (int8-+ 42 50))
(example (int8-compliment 7)) -- will be -8 because 2's complement

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(example (int8-compliment 7)) -- will be -8 because 2's complement
(example (int8-complement 7)) -- will be -8 because 2's complement

(example (+ 0b0111 0o22))
(example (+ 0b0111 0x7A))
10 changes: 5 additions & 5 deletions examples/free-identifier-case-test.kl
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
(syntax-case stx
[(list (_ x))
(free-identifier-case x
[if (pure '1)]
[else (pure '2)]
[define (pure '3)]
[#%app (pure '4)]
[if (pure '(the Integer 1))]
[else (pure '(the Integer 2))]
[define (pure '(the Integer 3))]
[#%app (pure '(the Integer 4))]
[(else y) (pure y)])]))]))

(define hello 32)
(define hello (the Integer 32))
(example (test if))
(example (test else))
(example (test define))
Expand Down
4 changes: 2 additions & 2 deletions examples/hygiene.kl
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
(let [,misc-id 'other]
x)))]))]))
(example
((should-be-id x) 5))
((should-be-id x) (the Integer 5)))

-- The following example demonstrates that we can have two (define x ...)
-- declarations with overlapping scopes without any accidental captures.
(define-syntax-rule (define-six misc-id)
(group
(define x "defined six")
(define misc-id 6)
(define misc-id (the Integer 6))
(example x)))
(define-six x)
(example x)
2 changes: 1 addition & 1 deletion examples/implicit-conversion.kl
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
-- everywhere, everything must expand to a Reader behind the scenes.

(define-macro (my-integer-literal n)
(pure `(reader-pure (#%integer-literal ,n))))
(pure `(reader-pure (the Integer (#%integer-literal ,n)))))

(define-macro (my-string-literal s)
(pure `(reader-pure (#%string-literal ,s))))
Expand Down
3 changes: 1 addition & 2 deletions examples/int-ops.kl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
(example (abs minus-two))
(example (abs 4))
(example (negate 4))
(example -4)
(example (the Integer -4))

(example (< 1 2))
(example (< 1 1))
Expand All @@ -32,4 +32,3 @@

(example (integer->string 4))
(example (integer->string (negate 5)))

3 changes: 1 addition & 2 deletions examples/integer-syntax.kl
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@
[_ (syntax-error (quasiquote/loc i "bad syntax"))])]
[_ (syntax-error (quasiquote/loc stx "bad syntax"))]))]))

(example (gotta-be-integer 2))

(example (the Integer (gotta-be-integer 2)))
2 changes: 1 addition & 1 deletion examples/lambda-case-test.kl
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
[(:: a b) 'cons]))

(example (classify (nil)))
(example (classify (:: 1 (:: 2 (nil)))))
(example (classify (:: (the Integer 1) (:: 2 (nil)))))
2 changes: 1 addition & 1 deletion examples/lambda-case.kl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
(let [f (lambda-case
[(nil) "nil"]
[(:: _ _) "cons"])]
(f (list 1 2 3))))
(f (list (the Integer 1) 2 3))))

-- A macro is implemented as a function of type (-> Syntax (Macro Syntax)).
-- Macro is a monad, but we don't make use of its effects in this example, so
Expand Down
8 changes: 4 additions & 4 deletions examples/list-test.kl
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
(import "list.kl")

(example
(foldr + 0 (list 1 2 3 4)))
(foldr + (the Integer 0) (list 1 2 3 4)))

(example
(map string-length (list "foo" "bar" "baz" "quux")))

(example
(filter (lambda (x) (< x 10))
(list 1 11 111 2 22 222 3 33 333)))
(list (the Integer 1) 11 111 2 22 222 3 33 333)))

(example
(snoc (list 1 2 3) 4))
(snoc (list (the Integer 1) 2 3) 4))

(example
(reverse (list 1 2 3)))
(reverse (list (the Integer 1) 2 3)))

(example
(syntax->list '(a b c)))
Expand Down
8 changes: 4 additions & 4 deletions examples/mcond-test.kl
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
(syntax-case stx
[(list (_ id))
(mcond
[(free-identifier=? id 'if) (pure '1)]
[(free-identifier=? id 'else) (pure '2)]
[(free-identifier=? id 'lambda) (pure '3)]
[(pure (true)) (pure '4)])]))]))
[(free-identifier=? id 'if) (pure '(the Integer 1))]
[(free-identifier=? id 'else) (pure '(the Integer 2))]
[(free-identifier=? id 'lambda) (pure '(the Integer 3))]
[(pure (true)) (pure '(the Integer 4))])]))]))

(example (test if))
(example (test else))
Expand Down
2 changes: 1 addition & 1 deletion examples/non-examples/no-case-matched.golden
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Error at phase p0: No case matched at no-case-matched.kl:4.3-6.10: (true)
Error at phase p0: No case matched at no-case-matched.kl:4.3-6.24: (true)
2 changes: 1 addition & 1 deletion examples/non-examples/no-case-matched.kl
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
(example
(case (true)
[(false)
42]))
(the Integer 42)]))
4 changes: 2 additions & 2 deletions examples/non-examples/type-errors/not-a-function.golden
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Type mismatch at not-a-function.kl:3.11-3.13.
Expected (Integer → (?1 → ?2)) but got Integer
Type mismatch at not-a-function.kl:3.24-3.26.
Expected (?1 → (?2 → ?3)) but got Integer

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since not-a-function.kl specifically annotates that the 42 has type Integer, I don't understand why the error message changed?

this is not a blocker.

2 changes: 1 addition & 1 deletion examples/non-examples/type-errors/not-a-function.kl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#lang "prelude.kl"

(example (42 4 2))
(example ((the Integer 42) 4 2))
6 changes: 3 additions & 3 deletions examples/pmatch.golden
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
(zero) : Nat
(zero) : Nat
(add1 (zero)) : Nat
(:: (pair #[pmatch.kl:119.34-119.35]<1> 1)
(:: (pair #[pmatch.kl:119.50-119.51]<2> 2)
(:: (pair #[pmatch.kl:119.66-119.67]<3> 3) (nil)))) : (List (Pair Syntax Integer))
(:: (pair #[pmatch.kl:119.48-119.49]<1> 1)
(:: (pair #[pmatch.kl:119.78-119.79]<2> 2)
(:: (pair #[pmatch.kl:119.108-119.109]<3> 3) (nil)))) : (List (Pair Syntax Integer))
2 changes: 1 addition & 1 deletion examples/pmatch.kl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,6 @@
[(nil)
(nil)]))

(example (swap-list (:: (pair 1 '1) (:: (pair 2 '2) (:: (pair 3 '3) (nil))))))
(example (swap-list (:: (pair (the Integer 1) '1) (:: (pair (the Integer 2) '2) (:: (pair (the Integer 3) '3) (nil))))))

(export pmatch)
Loading
Loading