Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

zkbpkp/liscript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LiScript

Lisp dialect written in Python

Installation

sudo pip3 install liscript

Usage

lirepl            # open liscript repl
lirun <filename>  # run liscript code

Overview

Syntax

;; Atoms
x         ; will return the value of variable `x'

;; Getters & properties
(:x obj)  ; will return property `x' of object (or dictionary) `obj'
obj:x     ; the same as above

;; Numbers
1
1.5
-1

;; Strings
"Hello, world!"

;; Expressions (lists)
(+ 1 2)                 ; apply function `+' to 1 and 2; will return 3

;; Quoted lists
'(1 (+ 1 1) (+ 1 1 1))  ; elements are evaluated when the list is initialized; will return '(1 2 3)

;; Lazy lists
[1 (+ 1 1) (+ 1 1 1)]   ; elements are evaluated manually; will return [1 (+ 1 1) (+ 1 1 1)]  

;; Dictionaries
{:x 1
 :y 2
 :z 3}

Standard functions

let, modify

> (let [x d] 0 {:a 1 :b 2})
> (let [d:c] 3)
> x
  -> 0
> d:c
  -> 3
> (modify [x] [+ 1])  ; same as `(let [x] (+ 1 x))'
> x
  -> 1

fn, def

> (def [sqr x] [* x x])   ; same as `(let [sqr] (fn [x] [* x x]))'
> (sqr 9)
  -> 81

class, new

> (class [Point] {:constructor (fn [self x y] [let [self:x] x] [let [self:y] y])})
> (let [p] (new Point 3 5))
> p:x
  -> 3
> p:y
  -> 5

+, -, *, /

> (+ 1 2)
  -> 3
> (- 5 1)
  -> 4
> (* 2 3)
  -> 6
> (/ 5 2)
  -> 2.5

>, <, =, !=

> (> 1 2)
  -> #f
> (< 5 1)
  -> #f
> (= 2 2)
  -> #t
> (!= 5 2)
  -> #t

if, unless, case

> (if #t [say "true"] [say "false"])
true
> (unless #t [say "true"] [say "false"])
false
> (case [= 1 0] [say "1 = 0"] [> 1 0] [say "1 > 0"] otherwise [say "1 < 0"])
1 > 0

list, cons

> (list 1 2 3)
  -> '(1 2 3)
> (cons 1 '(2 3))
  -> '(1 2 3)

head, tail

> (head '(1 2 3))
  -> 1
> (tail '(1 2 3))
  -> '(2 3)

push

> (push 3 '(1 2))
  -> '(1 2 3)

!!, slice

> (!! '(1 2 3) 1)
  -> 2
> (slice '(1 2 3 4 5 6 7 8 9 10) 5)
  -> '(6 7 8 9 10)
> (slice '(1 2 3 4 5 6 7 8 9 10) 1 5)
  -> '(2 3 4 5)

eval-list

> (eval-list '(+ 1 2))
  -> 3
> (eval-list [* 2 2])
  -> 4

say, read

> (read)
user input
  -> "user input"
> (say "hello, world")
hello, world

exit

> (exit)  ; exit with code 0

Releases

No releases published

Packages

No packages published

Languages