Schemelings

1. What this is

This is a project mostly for fun, but also to make it easier for other to understand and learn basic scheme.

I started with an interpriter and Gnu docs. It was honastly not the best expirience, and I am still learning a lot, but this is a way for me to clearify what and how some things work, and at the same time, hopefulle, someone else may learb something from it.

This is the webpage for my project, schemelings. The goal is to make something alike clings by tonybanters, or rustlings/ziglings.

2. Who it is for

Anarch

  • And whoever wishes to learn scheme and doesnt know it yet.

3. Extended recources

  1. SICP - uses scheme to explain computer sicience - https://web.mit.edu/6.001/6.037/sicp.pdf
  2. The Little Schemer - Uses food to explain recursion in a fun way - https://vbp.smallyu.net/%5BType%5D%20books/The%20Little%20Schemer.pdf

3.0.1. Some more are:

  1. Practical common lisp (about using lisp for software)
  2. On lisp (macros, solve your own problem)

3.0.2. Other recources are:

  1. Scheme.org, official scheme webiste
  2. The Guile Refrence Manual, written about how guile can be used and what guile has. Guile is Gnus scheme implementation they use themselves for things like gdb, fdisk, guix or sheppard.

4. Short definitions

  1. Prefix notation is where an opperator commes first followed by arguments, eg (+ 1 1), here is '+' the prefix
  2. Define the operator used to define global variables and datastorage, where functions++ can be said data
  3. Set! force redefine a definition erlier defined with (define …)
  4. Let same as define but local, lets you create isoleted variables that does not exist outside of the let expression.
  5. List A sequence of cons, or items stored togheter, like '(2 3 4 1), here it is a list of four numbers in one structure
  6. Quote A notation that tells the evaluator to treat it as literal data, and not as a function or something to evaluate
  7. Expression is everything that can and will get evaluated, for example (+ 1 1) or (define name "Alice")
  8. S-Expression a recurse expression storage, often wrapped in parantecies and consists of one atom, multiple atoms or a series of other S-expressions
  9. Procedure is something that takes an s-expression and returns another
  10. Lambda, one of the more important ones. It makes a procedure withouth binding it to just one name. This makes it more like an instructions manual than the mechanic. It takes arguments and a body (lambda (x y) (* x y)) tells it to take two values passed into it and return them multiplied by each other withouth giving it a name
  11. Recursion the act of calling itself to recure itself, like when done with this do it again from the start
  12. cons construct, pairs data
  13. Car takes first item, so (car '(4 3 2)) returns 4
  14. Cdr returns all but first item, (cdr '(4 3 2)) returns (3 2)
  15. Cond, scheme and lisps answer to switch or case. You first check if an expression returns #t (true) then if it's true it evaluates the expression after that (it alse has else as a if non true catch)

5. Examples

5.0.1. Display

(display "Hello, World!")
  1. Display sends the input to output, like printf in c

5.0.2. Define

(define name (read))
(display name)
  1. Define defines a function or variable globally.
  2. It takes a name and a value after, that value may be an atom or expression
  3. This makes it so that
(define (func x) (display x))
  1. Is the right way to make a global variable that displays whatever its passed.
  2. This can be as large or small as you wish

5.0.3. Basic math

(+ 1 2 3 4)
(- 4 1 3 2)
(* 3 2 1 2)
(/ 100 22 )
(/ 9.2 3.6)
  1. + is a prefix, and so is all of thsese, it adds the values passed
  2. - subtracts the first value by all the remainding ones
  3. * multicate all the values
  4. / with round numbers devide nonexact (if it doesn't return whole number it returns something like 23/2 insted of 11.5)
  5. / with decimal numbers devide exact (so it can return things like 11.5 too)

5.0.4. More math

(expt 3 3)
(sqrt 9)
(abs -5)
(max 6 2 3)
(min 6 2 3)
  1. expt takes the first number to the power of the secound, so here 33
  2. sqrt' takes the squareroot of the number
  3. abs get the abselute number, here it returns 5
  4. max returns the highest number
  5. min returns the lowest number

5.0.5. Number roudning

(floor 3.3)
(ceiling 3.4)
(truncate -3.3)
(truncate 3.3)
(round 3.4)
(round 2.5)
  1. floor rounds down
  2. ceiling rounds up
  3. truncate rounds in the direction of 0 (so in the example it will become -3 and 3)
  4. round rounds to nerest even

5.0.6. Equal or greater than

(= 3 4)
(< 3 4)
(> 3 4)
(>= 3 4)
(<= 3 4)
  1. = checks if same number
  2. < checks if the last is greater than first
  3. > checks if first is greater than last
  4. <= less than or equal
  5. >= less than or equal

5.0.7. Checks what kind of number

(inexact->exact 3.0)
(exact->inexact 3)
(number?    4)
(positive? -4)
(negative? -4)
(zero? 2)
(even? 2)
(odd?  2)
  1. inexact-> exact makes inexact number exact
  2. exact->inexact makes number inexact
  3. number? returns true or false dpending on if passed is a number
  4. positive? checks if number is positive
  5. negative? checks if number is negative
  6. zero? checks if number is zero
  7. even? chekcs if number is even
  8. odd? checks if number is odd

5.0.8. And/or/not

(not (= 0 0))
(and (= 3 3)
     (< 3 4))
(or  (= 2 3)
     (= 2 1))
  1. not returns #f if it get passed #f
  2. and returns #t if borh based are #t
  3. or returns #t if one or the other returns #t

5.0.9. Which data type

(integer? 42)
(string? "42")
(char? #\a)
(symbol? 'apple)
(boolean? #t)
(procedure? +)
(pair? '(2 2))
(null? '())
(number? 42)
(vector? #(2 . 1))
  1. integer? returns #t if get passed integer
  2. string? returns #t if get passed string
  3. char? returns #t if get passed char
  4. symbol? returns #t if get passed symbol
  5. boolean? returns #t if get passed boolean
  6. procedure? returns #t if get passed procedure
  7. pair? returns #t if get passed pair
  8. null? returns #t if get passed null
  9. number? returns #t if get passed number
  10. vector? returns #t if get passed vector

  1. The Data Types' short explernation
    1. integer is whole number
    2. string is a series of charachters in doubble quotes
    3. char is a single letter, charachter, number or whitespce with #\
    4. symbol is something treated as data, not as an expression
    5. boolean is a type for #t and #f
    6. procedure is any function
    7. pair is a list containing two values++
    8. null is empty list
    9. number is checks if number, does not matter type
    10. vector is a fixed size indexed array or list

5.0.10. If

(if (= 1 1)
    (+ 1 1)
    (- 1 1))
  1. If the first expression returns #t then:
    1. return eval or value of first
  2. if not true
    1. return the secound

5.0.11. Cond

(cond ((= 1 2) (+ 2 2))
      ((not (= 2 2)) (+ 2 3))
      (else (+ 2 4)))
  1. Cond takes any amount of arguments, it checks:
    1. is this true? yes, then eval this section, no then go to next
    2. This goes on as long as there are sections to check
    3. you can have an else that just says, if nothing else was true do this

Author: Alice (trondelagcutie@yahoo.com)

Date: 2026-02-02 ma. 00:00

Emacs 30.2 (Org mode 9.7.11)

Validate