Welcome to the CHICKEN Scheme pasting service

thread unsafe lists pasted by andyjpb on Fri Aug 17 16:14:36 2012


; this is in terms of ((client-name . ((client-sid . (session)) ...)) ...)
(define sessions '())

(define (insert-session client-name sid new-session)
  (let* ((clients-sessions (alist-ref client-name sessions equal?))
	 (clients-sessions (or clients-sessions '())))
    (set! sessions
      (alist-update! client-name
		     (alist-cons sid new-session clients-sessions)
		     sessions equal?))
    (pp sessions)))

(define (select-session client-name sid)
  (let* ((clients-sessions (alist-ref client-name sessions equal?)))
    (if clients-sessions
      (alist-ref sid clients-sessions equal?)
      #f)))


What alist-update! returns versus what it leaves in the original alist added by alaricsp on Fri Aug 17 16:21:18 2012

#;5> (define a '((foo . 1) (bar . 2)))
#;6> (define b (alist-update! 'baz 3 a))
#;7> a
((foo . 1) (bar . 2))
#;8> b
((baz . 3) (foo . 1) (bar . 2))
#;9> (define c (alist-update! 'baz 4 b))
#;10> a
((foo . 1) (bar . 2))
#;11> b
((baz . 4) (foo . 1) (bar . 2))
#;12> c
((baz . 4) (foo . 1) (bar . 2))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
Which procedure returns the number of elements in a list?
Visually impaired? Let me spell it for you (wav file) download WAV