all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Emanuel Berg <embe8573@student.uu.se>
To: help-gnu-emacs@gnu.org
Subject: Re: some more material on the Lisp data/code psychedelia
Date: Fri, 17 Jan 2014 02:29:06 +0100	[thread overview]
Message-ID: <87lhyf1jlw.fsf@nl106-137-194.student.uu.se> (raw)
In-Reply-To: 87mwjb2u4r.fsf@nl106-137-194.student.uu.se

;; Another classic demo for you all to vibe with.
;;
;; Sort of OO data/method encapsulation, and sort of
;; XML unrestricted markup, to do run-time data/type
;; consistency.
;;
;; (HELP! I'm a Lisp addict!)

;; version one
(setq *typed-symbol* '(0 integerp))

;; version two (combination of types)
(setq *typed-symbol* '(0.0 (lambda (val)
                             (or (floatp val)
                                 (integerp val) ))))
(fset
 '*typed-symbol*
 '(lambda (&optional new-data)
    (progn
      (if new-data
          (if (eval `(,(cadr *typed-symbol*) new-data))
              (setcar *typed-symbol* new-data)
            (error "Wrong type") ))
      (car *typed-symbol*) )))

(*typed-symbol*)     ; 0 (or 0.0), no change
(*typed-symbol* 4)   ; 4, cool
(*typed-symbol* 4.0) ; doesn't work for version one
(*typed-symbol* "disrespecting the type, man") ; error
(*typed-symbol*)     ; still 4 (or 4.0)

;; or, if desire to use a (half) normal variable:

(setq *integer-symbol* 1)

(fset
 '*integer-symbol*
 '(lambda (new-data)
    (if (integerp new-data)
        (setq *integer-symbol* new-data)
      (error "Wrong type: Integers only") )))

*integer-symbol*       ; 1
(*integer-symbol* 2)   ; 2
*integer-symbol*       ; 2
(*integer-symbol* 2.0) ; no floats
(*integer-symbol* "no strings") ; error

-- 
underground experts united:
http://user.it.uu.se/~embe8573


      reply	other threads:[~2014-01-17  1:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-04 19:37 some more material on the Lisp data/code psychedelia Emanuel Berg
2014-01-04 20:13 ` Thien-Thi Nguyen
     [not found] ` <mailman.11016.1388866201.10748.help-gnu-emacs@gnu.org>
2014-01-04 20:24   ` Emanuel Berg
2014-01-04 23:40     ` Emanuel Berg
2014-01-17  1:29       ` Emanuel Berg [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lhyf1jlw.fsf@nl106-137-194.student.uu.se \
    --to=embe8573@student.uu.se \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.