Skip to content

Instantly share code, notes, and snippets.

@guicho271828
Last active August 29, 2015 14:03
Show Gist options
  • Save guicho271828/715c5a15c72df6b2176e to your computer and use it in GitHub Desktop.
Save guicho271828/715c5a15c72df6b2176e to your computer and use it in GitHub Desktop.
(defun event-p (x) t) ;; constantly t
(defun key-p (x) t) ;; constantly t
;; w/o defpattern
(match event
((and (sdl:event- (type (eq :key-down-event)))
;;^^^^^^^^^^ this specify the container type
;;^^^^ this is a slot
;; ^^^^^^^^^^^^^^^^^^ and this specifies the type of the slot.
(sdl::key- (key (eq :sdl-key-z)) state)))
(format t "Z: ~A~%" state))
((and (sdl:event- (type (eq :key-down-event)))
(sdl::key- state)))
(format t "Down: ~A~%" state)))
((and (sdl:event- (type (eq :key-up-event)))
(sdl::key- state)))
(format t "UP: ~A~%" state)))
;; generalize it into defpattern
(defpattern sdl-event (type key state)
`(and (sdl:event- (type (eq ,type)))
(sdl::key- (key (eq ,key)) ,state)))
;; w/ defpattern
(match event
((sdl-event :key-down-event :sdl-key-z state)
(format t "Z: ~A~%" state))
((sdl-event :key-down-event _ state)
(format t "Down: ~A~%" state)))
((sdl-event :key-up-event _ state)
(format t "UP: ~A~%" state)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment