Styles in pseudo-code
We have to following procedure, that makes a list of all elements in list L that are smaller than N.
record item v next
define smallerthan in L in N out S
if L = NIL
S = NIL
else
smallerthan L.next N S
if L.v < N
new item E
E.v = L.v
E.next = S
S = E
We can write this in a function style using the instruction return,
that returns the value given by the argument.
record item v next
define smallerthan L N
if L = NIL
return NIL
else
S = smallerthan L.next N
if L.v < N
new item E
E.v = L.v
E.next = S
S = E
return S
And put this in a more functional language style.
(record item v next)
(define smallerthan L N
(if L = NIL
NIL
(if L.v < N
(new item L.v (smallerthan L.next N))
(smallerthan L.next N)
)
)
)