Python syntax in Lisp and Scheme
Pascal Bourguignon
spam at thalassa.informatimago.com
Thu Oct 9 18:30:21 EDT 2003
"Andrew Dalke" <adalke at mindspring.com> writes:
> Pascal Costanza:
> > So what's the result of ("one" - "two") then? ;)
>
> It's undefined on strings -- a type error. Having + doesn't
> mean that - must exist.
What about:
(defun nl-string-to-number (text)
;; Of course, you could program it more intelligently and more efficiently.
(do* ((i 0 (1+ i))
(s (format nil "~r" i) (format nil "~r" i))
)
((or (string-equal s text) (< (* 2 (length text)) (length s)))
(when (string-equal s text) i)))
);;nl-string-to-number
(defmacro def-s-op (name num-op)
`(defun ,name (&rest args)
(format nil "~r"
(apply (function ,num-op)
(mapcar (function nl-string-to-number) args))))
);;def-s-op
(def-s-op +s +)
(def-s-op -s -)
(def-s-op *s *)
(def-s-op /s /)
(def-s-op =s =)
(def-s-op /=s /=)
(def-s-op <s <)
(def-s-op <=s <=)
(def-s-op >s >)
(def-s-op =>s <=)
(-s "one" "two")
==> "minus one"
--
__Pascal_Bourguignon__
http://www.informatimago.com/
Do not adjust your mind, there is a fault in reality.
More information about the Python-list
mailing list