Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 35 |
Nodes: | 6 (0 / 6) |
Uptime: | 29:09:46 |
Calls: | 322 |
Calls today: | 1 |
Files: | 959 |
Messages: | 81,833 |
Posted today: | 3 |
You didn't run it, but it does not just compile in clisp (2019),
it works. SFY.
* zara <m2tt8wv3gm.fsf@freecol.be> :
Wrote on Fri, 14 Feb 2025 18:30:33 +0100:
You didn't run it, but it does not just compile in clisp (2019),
it works. SFY.
No it is still wrong and it will also fail with Clisp (if clisp does
ansi). it'll fail if you load another file with the same functionn
names.
(load "./dictionary.lisp");; Loading file ./dictionary.lisp ...
Madhu <enometh@meer.net> writes:
* zara <m2tt8wv3gm.fsf@freecol.be> :(defun make-dictionary ()
Wrote on Fri, 14 Feb 2025 18:30:33 +0100:
(let ((*dict ()))
(defun add (value)
(setq *dict (append *dict (list (length *dict) value))))
(defun get-with-index (index)
(let ((*index 0))
(loop for el in *dict
do (if (= (car el) index)
(return (cadr el))
(setq *index (+ 1 *index)))
(return ()))))
(defun dispatch (msg)
(cond ((eq msg 'add) #'add)
((eq msg 'get-with-index) #'get-with-index)
(T (print "make-dictionary : Message not understood"))
))
#'dispatch))
Hi,
Kaz Kylheku <643-408-1753@kylheku.com> writes:
On 2025-02-14, zara <johan@freecol.be> wrote:
Here's the example of the dictionary actor without CLOS :
Your approach has a giant bug, which is fixable.
;;
;; -- start of file --
;;
(defun make-dictionary ()
(let ((*dict ()))
(defun add (value)
(setq *dict (append *dict (list (length *dict) value))))
These defuns are defining and later redefining global function
bindings.
I know dynamic binding but using the actor there is little error.
Block scoping using the #'dispatch should almost always call
the defined add, get-with-index methods etc. not something
from environments above the lexical scope.
(I mean if you call a message from dispatch, you better define
your called method locally).
I know, but it was just an example. AFAIK I am correct, and you have a
new Actor system for Common Lisp (e.g. bare bones systems).
On 2025-02-14, zara <johan@freecol.be> wrote:
Hi,
Kaz Kylheku <643-408-1753@kylheku.com> writes:
On 2025-02-14, zara <johan@freecol.be> wrote:
Here's the example of the dictionary actor without CLOS :
Your approach has a giant bug, which is fixable.
;;These defuns are defining and later redefining global function
;; -- start of file --
;;
(defun make-dictionary ()
(let ((*dict ()))
(defun add (value)
(setq *dict (append *dict (list (length *dict) value)))) >>>
bindings.
I know dynamic binding but using the actor there is little error.
Block scoping using the #'dispatch should almost always call
the defined add, get-with-index methods etc. not something
from environments above the lexical scope.
I can't make heads or tails of this paragraph, but it sounds as if you
might be trying to convince me that your little coding tidbit isn't incorrect. Are /you/ even convinced?
Make a test case which makes two dictionaries:
(let ((dict1 (make-dictionary))
(dict2 (make-dictionary)))
...)
In the ... part, write some tests which show that an operation on
dict1 has no effect on a lookup in dict1.
(I mean if you call a message from dispatch, you better define
your called method locally).
That's the thing; you've not defined anything locally other
than the dict* variable.
defun is not a form which has a local effect.
I know, but it was just an example. AFAIK I am correct, and you have a
new Actor system for Common Lisp (e.g. bare bones systems).
In AFAIK, what exactly do you mean by K, know?
You are not correct, therefore if you "know" you are correct, there is something wrong with how you determine when you know something
and when you don't.
Hi,
just wanted to post the start of lisp-sound, there's a neat trick inside using
actors without CLOS, see the file dictionary.lisp for an example.
The code is here :
http://sf.net/projects/lisp-sound
On 2025-02-10, zara <johan@freecol.be> wrote:
Hi,
just wanted to post the start of lisp-sound, there's a neat trick inside using
actors without CLOS, see the file dictionary.lisp for an example.
If you want to discuss some piece of code here, it is best to just post
it here, in-line with your article.
The code is here :
http://sf.net/projects/lisp-sound
It's not 1999; nobody downloads tarballs from sourceforge to look
at your code.
Every time you do make-dictionary it updates its local *dict. You do not
You are not correct, therefore if you "know" you are correct, there is
something wrong with how you determine when you know something
and when you don't.
See the clisp output.
(defun make-dictionary ()(let ((*dict ()))
(defvar d0 (make-dictionary))D0
(funcall (funcall d0 'add) 'apple)(0 APPLE)
(funcall (funcall d0 'add) 'banana)(0 APPLE 2 BANANA)
(funcall (funcall d0 'add) 'orange)(0 APPLE 2 BANANA 4 ORANGE)
(defvar d1 (make-dictionary)) ;; make new dict, continue with d0D1
(funcall (funcall d0 'add) 'peach)(0 PEACH)
Here's the example of the dictionary actor without CLOS :
;;
;; -- start of file --
;;
(defun make-dictionary ()
(let ((*dict ()))
(defun add (value)
(setq *dict (append *dict (list (length *dict) value))))
;; tests
;(setf dictionary (make-dictionary))
;(print (funcall (funcall dictionary "add") 255))
;;
;; -- end of file --
;;
I had to change two parens to make it compile.
The tests ran in clisp in 2019.
On 2025-02-14, zara <johan@freecol.be> wrote:
Here's the example of the dictionary actor without CLOS :
Your approach has a giant bug, which is fixable.
;;
;; -- start of file --
;;
(defun make-dictionary ()
(let ((*dict ()))
(defun add (value)
(setq *dict (append *dict (list (length *dict) value))))
These defuns are defining and later redefining global function
bindings.
You need
(let ((*dict ()))
(labels ((add (value) ...)
(get-with-index (index) ...)
(dispatch (msg)
(case msg
(add #'add)
(get-with-index #'get-with-index))
(t (error "make-dictionary: ...."))))
#'dispathch))
(Labels defines lexical functions. So does its sister, flet.
Functions defined in the same labels block can see each other
and call each other. Those defined by flet cannot; they see
only functions outside of the flet.)
Alternatively, we could use variable bindings, whose values
are closures created by lambda:
(let ((*dict ()))
(let* ((add (lambda (value) ...))
(get-with-index (lambda (index) ...))
(dispatch (lambda (msg)
(case msg
(add add)
(get-with-index get-with-index))
(t (error "make-dictionary: ....")))))
dispatch))
It's more verbose with the (lambda ...) but we lose the #'.
Note how I used (error ...) for the unrecognized message
case, which signals a condition, and not (print ...).
printing is amateurish. It does nothing to indicate to the
caller that something went wrong, only logs a message and
keeps going. The end user of the application won't even
see the message if it's a GUI unless they know to peek into
some certain console window or whatever. If they see it,
they won't know what to do.
;; tests
;(setf dictionary (make-dictionary))
;(print (funcall (funcall dictionary "add") 255))
What result are you expecting from this test case?
The string "add" and symbol add are different objects,
and so (eq "add" 'add) is false; this will not dispatch
the add method.
;;
;; -- end of file --
;;
I had to change two parens to make it compile.
The tests ran in clisp in 2019.
You forgot to write a test which shows that operations on one dictionary
have no effect on the apparent contents of another.
Also, your dictionary is inefficient; Common Lisp already has
hash tables.