Atom

  • atomWhat is the
  • atomIt’s an atom
  • turkeyIt’s also an atom
  • 1992It’s also an atom
  • bIt’s also an atom
  • *abc$It’s also an atom
  • (a)It’s not an atom, it’s an empty list

List

  • (a)Is an empty list
  • (atom)It’s a list
  • (atom atom2)It’s also a list
  • (atom atom2) noIt’s not a list
  • ((atom atom2) no)It’s a list

S-expression

  • abcExpression of S –
  • ((atom atom2) no)Expression of S –
  • (a b c)Expression of S –
  • ((a b c) (e f) (d) e)Expression of S –
  • (a)isExpression of S –
  • () () ()Expression of S –

function

  • car
    • Fetch the first member of the list
    • Parameters: a non-empty list,(a)saidAn empty list
    • Example,a b cIt’s all atoms,(a b c)The said list
      • (car (a b c)) => a
      • (car ((a b) c)) => (a b)
      • (car ((a d) (b c)) => (a d)
      • (car (() b c) => ()
      • (car () )Parameter cannot beAn empty list
      • (car abc)Parameter cannot beatomic
  • cdr
    • Returns a list, but the new list does not contain the first member of the original list
    • Arguments: a non-empty list
    • Example,a b cIt’s all atoms,(a b c)The said list
      • (cdr (a b c)) => (b c)
      • (cdr ((a b) c)) =>(c)
      • (cdr ((a b) (c d))) =>( (c d) )
      • (cdr (() b c)) =>(b c)
      • (cdr ())Parameter cannot beAn empty list
      • (cdr abc)Parameter cannot beatomic
  • cons
    • Take the first argument, put it in the first position of the list, and get a new list
    • Parameters: YesTwo parameters, the first parameter can be anyExpression of S –The second argument is any list (includingAn empty list)
    • example
      • (cons a ()) => (a)
      • (cons a (b c)) => (a b c)
      • (cons a ((b c) d)) => (a (b c) d)
      • (cons (a b c) ()) =>((a b c))
      • (cons (a b c) (d)) =>((a b c) d)
      • (cons (a b) c)The second argument cannot beatomic
  • null?
    • Check whether the list is empty
    • Parameter: Takes one parameter, which can be any list (including empty list)
    • example
      • (null? ()) => true
      • (null? (a b c)) => false
      • (null? abc )Parameter cannot beatomic
  • atom?
    • Check whether the s-expression is atomic
    • Parameter: Can take one parameter, which can be any S-expression
    • Example:
      • (atom? a) => true
      • (atom? ab) => false
      • (atom? bss) => true
      • (atom? ()) => false
      • (atom? (a b c)) => false
  • eq?
    • Meaning: to determine whether two atoms are the same
    • Parameter: Can take two parameters, and both parameters must be atoms, but cannot be numeric atoms
    • Example:
      • (eq? a a) => true
      • (eq? a b) => false
      • (eq? aa aa) => true
      • (eq? (a) (a))parameterIt can’t be a list
      • (eq? a (a))parameterIt can’t be a list
      • (eq? 123, 123).parameterIt can’t be a numeric atom