Language Reference Scheme 48
1 Bindings Examples
2 The Datatypes - primitives /   base types
3 The Datatypes - functions
4 The Datatypes - Pairs/  Lists
4.1 Pairs
4.2 Lists
4.3 Characters
4.4 Strings
4.5 Vectors

Language Reference Scheme 48🔗

Harald Glab-Plhak <hglabplhak@gmail.com>

Note: This reference is to have a complete overview of Scheme 48 it’s base types, functionality and the different API’s Scheme48 homepage / sources, documentation, links.

    1 Bindings Examples

    2 The Datatypes - primitives / base types

    3 The Datatypes - functions

    4 The Datatypes - Pairs/Lists

      4.1 Pairs

      4.2 Lists

      4.3 Characters

      4.4 Strings

      4.5 Vectors

#lang scribble/doc

1 Bindings Examples🔗

Harald Glab-Plhak <hglabplhak@gmail.com>

Here we define the potential environment operations for bindings:

(define add 'add)
(define remove 'remove)
(define push-frame 'push-frame)
(define pop-frame 'pop-frame)

Have a look how such functionality may be defined

procedure

(binding id value) → function?

  id : string?
  value : any?/c
This function takes a id as first parameter and any value function or another binding as second parameter and returns a function containing the binding

Example:
(define binding (lambda (id value)
     (let ([int-id id]
           [int-value value])
     (lambda ()
       (cons int-id int-value)))))

procedure

(frame-it frame binding) → list?

  frame : list?
  binding : cons?
This function takes a frame and a new binding and adds the binding to the frame newly created and given back so the binding is part of this frame which normaly is the actual environment level

Example:
(define frame-it (lambda (frame binding)
   (let ([new-frame (append frame (list binding))])
     new-frame)))

procedure

(environment) → function?

This function takes no arguments it is the function to return a function representing the quasi singleton of an environment which holds the frames and inside the frame the stack and the bindings which are newly created entering a new block and the existing block is pushed back after leaving the block the actual environent is thrown away and the last environment (frame) is popped from stack

Example:
(define environment (lambda ()
(let ([act-frame (frame-it 'dummy 'new-val)]
      [frames (list)])
 
(lambda (cmd id value)
(cond ((eq? cmd add)
(set! act-frame (frame-it act-frame id value)))
((eq? cmd remove)
 'none)
((eq? cmd push-frame)
 (begin
  (set! frames (append frames act-frame))
  (set! act-frame (frame-it 'dummy 'new-val)))))))))

This example is not complete but you can see a bit how bindings frames and different levels of environments can be handled if you are interested to learn more about this mechanismn you can read for example the articles of Mr. Landine about the SECD machine concept

#lang scribble/doc

2 The Datatypes - primitives / base types🔗

3 The Datatypes - functions🔗

The basic datatypes like Integer , Boolean, Long, Float Double and the base functions

procedure

(not value) → boolean?

  value : any/c
This function takes a value as parameter and reverts the case of #t to #f

procedure

(eq? x y) → boolean?

  x : any/c
  y : any/c
This function takes a first value x as first parameter and a second value x and compares them for equality

procedure

(eqv? x y) → boolean?

  x : any/c
  y : any/c
This function takes a first value x as first parameter and a second value x and compares them for equality

procedure

(equal? x y) → boolean?

  x : any/c
  y : any/c
This function takes a first value x as first parameter and a second value x and compares them for equality

procedure

(max first rest ...) → number?

  first : number?
  rest : number?
This function takes a first value first as first parameter and a second or 0..n value(s) rest And here the highest value is returned

procedure

(min first rest ...) → number?

  first : number?
  rest : number?
This function takes a first value first as first parameter and a second or 0..n value(s) rest And here the lowest value is returned

procedure

(abs num) → number?

  num : number?
This function takes a number and returns the absolute which is than positive

procedure

(zero? x) → boolean?

  x : number?
This function takes a nomber and checks if it is zero

procedure

(positive? x) → boolean?

  x : number?
This function takes a nomber and checks if it is positive

procedure

(negative? x) → boolean?

  x : number?
This function takes a nomber and checks if it is negative

procedure

(even? x) → boolean?

  x : number?
This function takes a nomber and checks if it is even

procedure

(odd? x) → boolean?

  x : number?
This function takes a nomber and checks if it is odd

4 The Datatypes - Pairs/Lists 🔗

procedure

(car l) → any/c

  l : list?
takes the first element of a list from start of the list

procedure

(cdr l) → list?

  l : list?
takes the rest element(s) of a list all elements after the first element

4.1 Pairs🔗

procedure

(cons e1 e2) → pair?

  e1 : any/c
  e2 : any/c
constructs a pair out of two given elements to get a object which is a pair? as well as a list?

procedure

(pair? element) → pair?

  element : any/c
Tests if the element is a pair Examples:

(pair? (cons 5 6)) -> #t (pair? (list 5 6)) -> #t (pair? (list 5)) -> #f (pair? '(5 6)) -> #t (pair? '(5)) -> #f (pair? '()) -> #f (pair? 5) -> #f

4.2 Lists🔗

Here are some abbreviations which can be useful:

procedure

(caar x) → any/c

  x : list?
Implemented as: (car (car x))

procedure

(cadr x) → any/c

  x : list?
Implemented as: (car (cdr x))

procedure

(cdar x) → list?

  x : list?
Implemented as: (cdr (car x))

procedure

(cddr x) → list?

  x : list?
Implemented as: (cdr (cdr x))

procedure

(caaar x) → any/c

  x : list?
Implemented as: (caar (car x))

procedure

(caadr x) → any/c

  x : list?
Implemented as: (cadr (car x))

procedure

(caddr x) → list?

  x : list?
Implemented as: (cddr (cdr x))

procedure

(cdaar x) → any/c

  x : list?
Implemented as: (cdar (car x))

procedure

(cdadr x) → list?

  x : list?
Implemented as: (cdar (cdr x))

procedure

(cddar x) → any/c

  x : list?
Implemented as: (cddr (car x))

procedure

(cdddr x) → list?

  x : list?
Implemented as: (cddr (cdr x))

procedure

(caaaar x) → any/c

  x : list?
Implemented as: (caaar (car x))

procedure

(caaadr x) → list?

  x : list?
Implemented as: (caaar (cdr x))

procedure

(caadar x) → any/c

  x : list?
Implemented as: (caadr (car x))

procedure

(caaddr x) → list?

  x : list?
Implemented as: (caadr (cdr x))

procedure

(cadaar x) → any/c

  x : list?
Implemented as: (cadar (car x))

procedure

(cadadr x) → list?

  x : list?
Implemented as: (cadar (cdr x))

procedure

(cdaadr x) → list?

  x : list?
Implemented as: (cdaar (cdr x))

procedure

(cdadar x) → any/c

  x : list?
Implemented as: (cdadr (car x))

procedure

(cddaar x) → any/c

  x : list?
Implemented as: (cddar (car x))

procedure

(cddadr x) → list?

  x : list?
Implemented as: (cddar (cdr x))

procedure

(cddaar x) → any/c

  x : list?
Implemented as: (cddar (car x))

procedure

(cdddar x) → any/c

  x : list?
Implemented as: (cdddr (car x))

procedure

(cddddr x) → list?

  x : list?
Implemented as: (cdddr (cdr x))

procedure

(null? l) → boolean?

  l : list?
checks if the list is empty ’()

procedure

(list x ...) → list?

  x : any/c
creates a list

procedure

(length l) → integer?

  l : list?
the effective length of a list (element count)

procedure

(append l lists ...) → list?

  l : list?
  lists : list?
append lists to a list and return the result

procedure

(reverse l) → list?

  l : list?
reverts the order of the elements in a list

procedure

(list-tail l index) → list?

  l : list?
  index : integer?
returns the tailing list of the list up from index

procedure

(list-ref l index) → any/c

  l : list?
  index : integer?
returns the element at index

procedure

(member v l) → (or/c #f list?)

  v : any/c
  l : list?
Locates the first element of the list that is equal to v according to equal?. If such an element exists, the tail of lst starting with that element is returned. Otherwise, the result is #f.

procedure

(memq v l) → (or/c #f list?)

  v : any/c
  l : list?
Same as member with the difference that eq? is used instead of equal?

procedure

(memv v l) → (or/c #f list?)

  v : any/c
  l : list?
Same as member with the difference that eqv? is used instead of equal?

procedure

(assoc v l) → (or/c pair? #f)

  v : any/c
  l : (listof pair?)
Locates the first pair of the list where the key is equal? to v and returns it if no match is found it returns #f

procedure

(assq v l) → (or/c pair? #f)

  v : any/c
  l : (listof pair?)
Same as assoc with the difference that eq? is used instead of equal?

procedure

(assv v l) → (or/c pair? #f)

  v : any/c
  l : (listof pair?)
Same as assoc with the difference that eqv? is used instead of equal?

procedure

(list? thing) → (boolean?)

  thing : any/c
Ask if thing is a list

4.3 Characters🔗

procedure

(char<? first second) → (boolean?)

  first : char?
  second : char?
Look if first char is smaller than second char

procedure

(char>? first second) → (boolean?)

  first : char?
  second : char?
Look if first char is greater than second char

procedure

(char<=? first second) → (boolean?)

  first : char?
  second : char?
Look if first char is smaller or equal second char

procedure

(char>=? first second) → (boolean?)

  first : char?
  second : char?
Look if first char is greater or equal second char

4.4 Strings🔗

procedure

(string ...) → (string?)

define a string out of strings

procedure

(substring str start end) → (string?)

  str : string?
  start : integer?
  end : integer?
The substring of str starting with start offset and ending end offset

procedure

(string-append ...) → (string?)

Concat one or more strings to one string

procedure

(string-length arg) → (integer?)

  arg : string?
The length of arg

procedure

(string-ref str index) → (char?)

  str : string?
  index : integer?
The string reference of str at the index position index the return is the char at that position

procedure

(string->list arg) → (list?)

  arg : string?
The string arg is converted to a list of chars

procedure

(list->string arg) → (string?)

  arg : list?
The list of chars arg is converted to a string

procedure

(string-fill! v x) → (unspecific)

  v : string?
  x : char?
The string v is filled with the char x

procedure

(string=? str1 str2) → (boolean?)

  str1 : string?
  str2 : string?
Ask if the string str1 is case sensitive equal to str2 return true if it is or false if not

procedure

(string<=? str1 str2) → (boolean?)

  str1 : string?
  str2 : string?
Ask if the string str1 is case sensitive smaller than or equal to str2 return true if it is or false if not

procedure

(string>=? str1 str2) → (boolean?)

  str1 : string?
  str2 : string?
Ask if the string str1 is case sensitive greater than or equal to str2 return true if it is or false if not

procedure

(string>? str1 str2) → (boolean?)

  str1 : string?
  str2 : string?
Ask if the string str1 is case sensitive greater than str2 return true if it is or false if not

procedure

(string<? str1 str2) → (boolean?)

  str1 : string?
  str2 : string?
Ask if the string str1 is case sensitive smaller than str2 return true if it is or false if not

procedure

(string-ci=? str1 str2) → (boolean?)

  str1 : string?
  str2 : string?
Ask if the string str1 is case insensitive equal to str2 return true if it is or false if not

procedure

(string-ci>=? str1 str2) → (boolean?)

  str1 : string?
  str2 : string?
Ask if the string str1 is case insensitive greater than or equal to str2 return true if it is or false if not

procedure

(string-ci<=? str1 str2) → (boolean?)

  str1 : string?
  str2 : string?
Ask if the string str1 is case insensitive smaller than or equal to str2 return true if it is or false if not

procedure

(string-ci<? str1 str2) → (boolean?)

  str1 : string?
  str2 : string?
Ask if the string str1 is case insensitive smaller than str2 return true if it is or false if not

procedure

(string-ci>? str1 str2) → (boolean?)

  str1 : string?
  str2 : string?
Ask if the string str1 is case insensitive greater than str2 return true if it is or false if not

#lang scribble/doc

#lang scribble/doc

4.5 Vectors🔗