# Bigger scheme - sam's capsule: sloum's small s-expression based language ``` / \ / k --- a b --- f / \ / \ me --- l i \ / \ / j --- c d --- e \ / g --- h ``` ... a.k.a. 'slope' - a Scheme-like (according to the author R4RS-ish), still a Work-In-Progress, but it already implements a significant subset of the specification. Plus some extras. Plus some networking. Plus more extras...) ## Why is it interesting? ... you might ask -- I already know C and/or Python and/or Javascript and/or whatever-is-cool-in-programming-this-week. Sure you know it, but... Well, back then, in the old days it was kind of a good taste for a programmer to try to write some stuff using different paradigms. Some procedural FORTRAN or BASIC (yes, BASIC was a valid language back then), some low-level programming in an assembly language, something with curly braces (C, later C++...), and then in the end - an equivalent of the knighthood - Lots of Irritating Superfluous Parentheses^W^W^W^W^W I mean LISP, a list based language, seen back then as humanity's last hope in the quest for an artificial intelligence. Well, Scheme is much more fun than LISP. And doing Scheme in SloPE is even more fun... ## Why is it more fun? I doubt someone who never wrote anything in LISP, Scheme or Racket will accomplish impossible using 'slope'. But "wrapping one's mind" around it, trying to solve known problems using different methods is fun. What I am trying to say is ## It's like a puzzle How does it work - what is that 'list based' thing? And again, why is it supposedly more fun than other LISP dialect? List based? Because everything is a list - your data, your functions, your whole program. More fun? Because it's easy to write something in a language that gives you everything? Wanna write a web server in PHP? Here we go: ``` php -S 192.168.1.1:8080 ``` Done. Now you can see your current folder in your browser. Easy? Yes. Fun? Eeeekk... not really. ## How does this 'slope' thing look like? Hmmm... Lot's of parentheses ;-) A rather limited set of commands. Simple, very simple syntax. Yes, you guessed right. *Lists* ## Let's make it even weirder ... and use a list based language to implement a simple stack based calculator ;) => https://git.rawtext.club/sloum/slope/src/branch/master/README.md For now the whole documentation is here... and in the code itself You can find a lot of Scheme related material in the internet of course => http://www.shido.info/lisp/scheme4_e.html Like this... ## Let's write some weird code ``` slope $ cat stack.slo (define Stack '()) (define PUSH (lambda (val) (set! Stack (cons val Stack)))) (define POP (lambda () (begin0 (car Stack)(set! Stack (cdr Stack))))) (define PEEK (lambda () (if (not (null? Stack)) (display (car Stack))))) (define ADD (lambda () ( begin0 (+ (car Stack) (car (cdr Stack))) (set! Stack (cdr (cdr Stack)))))) (define SUB (lambda () ( begin0 (- (car (cdr Stack)) (car Stack)) (set! Stack (cdr (cdr Stack)))))) (define MUL (lambda () ( begin0 (* (car Stack) (car (cdr Stack))) (set! Stack (cdr (cdr Stack)))))) (define DIV (lambda () ( begin0 (/ (car (cdr Stack)) (car Stack)) (set! Stack (cdr (cdr Stack)))))) ``` ... and run it: ``` slope $ ./slope ┌─┐┬ ┌─┐┌─┐┌─┐ └─┐│ │ │├─┘├┤ └─┘┴─┘└─┘┴ └─┘ Build Version Hash/Commit: b4a74dc05c1640532e49c35061ddf429681959db (c) 2021 sloum, see license with: (license) Type (exit) to quit > (load "stack.slo") #1=> ok > (PEEK) #2=> () > (PUSH 355) #3=> ok > (PUSH 113) #4=> ok > (DIV) #5=> 3.1415929203539825 > (exit) slope $ ``` Not the easiest way to calculate pi, but much more fun than Python's: ``` import math print (math.pi) ``` ## Get it here => https://git.rawtext.club/sloum/slope Gitea repository