Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Janet: a lightweight, expressive and modern Lisp. Parent comment
(see tutorial: http://stefano.dissegna.me/cells-tutorial.html, and documentation: https://gitlab.common-lisp.net/cells/cells/-/tree/master/doc)
(ql:quickload :cells) (defpackage :robot (:use :cl :cells)) (in-package :robot)
(defmodel robot () ((command :accessor command :initform (c-in nil)) (velocity :initform (c? (case (command self) (:left -10) (:right 10) (t 0))))))
(defun log-change (what from to) (print `(:change ,what :from ,from :to ,to) *debug-io*)) (defobserver velocity ((model robot) new old boundp) (when boundp (log-change `(velocity ,model) old new)))
(let ((w (make-instance 'robot))) (setf (command w) :right) (setf (command w) :left) (setf (command w) nil))
(:CHANGE (VELOCITY #<ROBOT {1015D66783}>) :FROM 0 :TO 10) (:CHANGE (VELOCITY #<ROBOT {1015D66783}>) :FROM 10 :TO -10) (:CHANGE (VELOCITY #<ROBOT {1015D66783}>) :FROM -10 :TO 0)
There are no comments on this comment yet.
(see tutorial: http://stefano.dissegna.me/cells-tutorial.html, and documentation: https://gitlab.common-lisp.net/cells/cells/-/tree/master/doc)
Define a robot model (class) where command in an input, and velocity is defined by an update rule: Whenever command is modified, velocity is updated accordingly. You can add observers for slot changes: Then, if you instanciate the model, and mutate the command slot: The following is logged: Anyway, the book Common Lisp Recipes (E. Weitz) is good for solving actual, pratical problems with Lisp.