Skip to content

Instantly share code, notes, and snippets.

@shelling
Created September 18, 2009 15:59
Show Gist options
  • Select an option

  • Save shelling/189134 to your computer and use it in GitHub Desktop.

Select an option

Save shelling/189134 to your computer and use it in GitHub Desktop.
exam mutating parameters itself
;; SEE ALSO
;; http://stackoverflow.com/questions/1080328/append-in-scheme
(define foo '(hello world))
(append! foo '(bar))
(display foo)(newline)
(define my-append!
(lambda (a . b)
(if (null? (cdr a))
(set-cdr! a b)
(my-append! (cdr a) (car b)))))
(my-append! foo 'my-append)
(display foo)(newline)
(define push
(lambda (lst . varr)
(append! lst varr)))
(define mypush
(lambda (lst . varr)
(if (null? (cdr lst))
(set-cdr! lst varr)
(mypush (cdr lst) (car varr)))))
(push foo 'new 'push 'way)
(display foo)(newline)
(mypush foo 'mypush 'way)
(display foo)(newline)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment