guise-lang/examples/basic.guise

42 lines
775 B
Plaintext
Raw Normal View History

2025-11-07 00:08:50 -05:00
;;; Basic Guise Examples
;;; Demonstrates core language features
;;; Simple arithmetic
(5 3 +) ; → 8
;;; Stack operations
(5 dup *) ; → 25 (square)
;;; Word definition
(define square (number -> number)
(dup *))
;;; Using defined words
(7 square) ; → 49
;;; Quotations (code blocks)
'(1 +) ; Push quotation onto stack
;;; Call quotation
(5 '(1 +) call) ; → 6
;;; Conditionals
(define abs (number -> number)
(dup 0 < '(neg) '() if))
(5 abs) ; → 5
(-5 abs) ; → 5
;;; Multiple operations
(3 4 + 2 *) ; → 14
;;; Comparison
(5 3 >) ; → #t
(2 2 =) ; → #t
;;; Stack combinators
(define twice ('a (quot ('a -> 'a)) -> 'a)
(dup call call))
(5 '(1 +) twice) ; → 7