[Ecls-list] map iterator

Marco Antoniotti marcoxa at cs.nyu.edu
Thu Nov 10 08:25:01 UTC 2005


On Nov 10, 2005, at 6:44 AM, Dean O'Connor wrote:

>
> Bring on the plug !!!
>
> Good stuff, that package looks like just what I am after. Cheers Marco.
>
> Got the tarball, but bit lost with the install install instructions.
> I have build ECL with ASDF support, but don't know how to get these  
> cmds to work.
>
> (mk:load-system "enumerations")
> (asdf-install:install "enumerations")

I usually build my systems with MK:DEFSYSTEM.  ECL comes with  
MK:DEFSYSTEM (or at least it did).

ASDF-INSTALL works only if you have the patched version that works with  
MK:DEFSYSTEM (you should be able to get it in the usual place)

Sice we are at it,  I will add a couple of bells and whisltes to the  
CL-ENUMERATION package, in order to make it easier to install.

Cheers
--
Marco




>
> Anyway I have just loaded the lisp files directory. Seem ok.
> Will give it a decent test tomorrow.
>
> Btw, Juanjo, I appreciated what you said in your response also, but  
> understand that my quest for iterators was one driven by necessity,  
> not some fanciful replication of C++ idioms :)
>
> Our aim is to replace single threaded processing of trade data,  
> currently done with EMACS-LISP interpreter embedded into our C++  
> server app, with an interpreter than can handle multithreaded so we  
> can take advantage of multiple processor boxes and process trades  
> concurrently. The driving force is to improve speed.
>
> The C++ server is rather large and complex and I am litterally  
> surgically cutting out the old interpreter hooks and and replacing it  
> with ECL.
> It would be cool to attempt to push more of the server's logic into  
> the Lisp world, but alas most has to stay, if not for just sheer  
> effort reasons.
> We are attempting to use the ECL interpreter to process trade data  
> which is still in massive C++ datastructures.
>
> Its difficult to express without going into much detail, but I reached  
> a point in the C++ app where in a existing C++ function I need to loop  
> and access all my per-thread binded Lisp hash-table items iteratively.
> Changing the C++ function was not really an option, so I needed an  
> iterator of sorts.
>
> Just before Marco tabled his plug, I realised I could prob fudge it by  
> passing pointer of C stucture (on stack) to a Lisp function which in  
> turn calls a call-back C function and uses that stack pointer to  
> continue its work.
> But if Marco's stuff kicks, it should look alot cleaner.
>
> I have to say, in these last few weeks I have grown to appreciate Lisp  
> and really hope this works out.
>
> Cheers for your help as always :)
> Dean.
>
> Marco Antoniotti wrote:
>
>> Shameless plug. :)
>>
>> http://common-lisp.net/project/cl-enumeration
>>
>> Marco
>>
>> On Nov 9, 2005, at 3:35 AM, Dean O'Connor wrote:
>>
>>>
>>> Hi
>>>
>>> I am having trouble finding a way to accomplish something in Lisp,  
>>> perhaps someone has ideas ....
>>>
>>> I am trying to implement the functional equivalent an C++ iterator  
>>> to an STL map class, in Lisp.
>>> I need this as I have a C++ application function that needs to call  
>>> a lisp function iteratively to retrieve all key/value mappings.
>>> So I need to able to call a Lisp function that will return be the  
>>> next map pair.
>>>
>>> From my limited experience in Lisp, hash tables seemed to be the  
>>> obvious choice. (This could be my first wrong assumption !)
>>> So I created a class containing a hash table and methods to add,  
>>> show all and an attempt at a iterator for retrieval.
>>>
>>> Now perhaps I am stupidly overcomplicated the matter, but reading  
>>> all I could on hash-tables, I didn't see an easy way to index or  
>>> remember where I was up to iterating thru the hash over seperate  
>>> function calls.
>>>
>>> I did find a link that encouraged me to use closures (still quite  
>>> voodoo to me :) to accomplish it.
>>> However on this link (below), it did warn about the following:
>>>
>>> http://www.cs.queensu.ca/software_docs/gnudev/gcl-ansi/gcl_1059.html
>>>
>>> >> "It is unspecified what happens if any of the implicit interior  
>>> state of an iteration is returned outside the dynamic extent of the  
>>> *with-hash-table-iterator* /form/ such as by returning some  
>>> /closure/ over the invocation /form/."
>>>
>>> Now my example nearly works (incorrectly returns FIRST pair for both  
>>> calls)  but its pretty clear to me my closure is not remembering the  
>>> state of the "with-hash-table-iterator".
>>> I am pretty sure I haven't done enough syntactically for it to work  
>>> poperly, but also I was wondering if there is any official word of  
>>> the behaviour of this form in ELCS ?
>>>
>>> If my approach is all wrong, does anyone have any suggestions.
>>>
>>> ;-------------------------------------------------------------------- 
>>> -
>>> ; Class: mapper-class
>>> ;-------------------------------------------------------------------- 
>>> -
>>>
>>> (defclass mapper-class ()
>>>  ((hash-table
>>>    :initform (make-hash-table)
>>>    :accessor table)
>>>   (iterator
>>>   :initform nil
>>>   :accessor it)))
>>>
>>> ;-------------------------------------------------------------------- 
>>> -
>>> ; Methods: mapper-class
>>> ;-------------------------------------------------------------------- 
>>> -
>>>
>>> (defmethod show ((m mapper-class))
>>>
>>>  (with-accessors ((ht table)) m
>>>          (maphash #'(lambda (k v) (format t "~a => ~a~%" k v)) ht)))
>>>
>>> (defmethod add ((m mapper-class) key value)
>>>  (with-accessors ((ht table)) m
>>>          (setf (gethash key ht) value)))
>>>
>>> (defmethod clear ((m mapper-class))
>>>  (with-accessors ((ht table)) m
>>>          (clrhash ht)))
>>>
>>> (defmethod set-start ((m mapper-class))
>>>  (with-accessors ((ht table) (it it)) m
>>>          (setf it #'(lambda ()
>>>                   (with-hash-table-iterator (next-entry ht)
>>>                             (next-entry))))))
>>>
>>> (defmethod get-next ((m mapper-class))
>>>  (with-accessors ((it it)) m
>>>          (multiple-value-bind (more key value)
>>>              (funcall it)
>>>            (if more
>>>            (cons key value)
>>>              nil))))
>>>
>>> ;-------------------------------------------------------------------- 
>>> -
>>> ; Example of populating and retrieving key/values
>>> ;-------------------------------------------------------------------- 
>>> -
>>>
>>> (defparameter *map1* (make-instance 'mapper-class))
>>>
>>> (add *map1* "key1" "val1")
>>> (add *map1* "key2" "val2")
>>>
>>> (show *map1*)
>>> (set-start *map1*)
>>>
>>> (setf key-val (get-next *map1*))
>>> (format t "~a => ~a~%"  (first key-val) (rest key-val))
>>>
>>> (setf key-val (get-next *map1*))
>>> (format t "~a => ~a~%"  (first key-val) (rest key-val))
>>>
>>>
>>> Cheers
>>> Dean.
>>>
>>>
>>> -------------------------------------------------------
>>> SF.Net email is sponsored by:
>>> Tame your development challenges with Apache's Geronimo App Server.  
>>> Download
>>> it for free - -and be entered to win a 42" plasma tv or your very own
>>> Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
>>> _______________________________________________
>>> Ecls-list mailing list
>>> Ecls-list at lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/ecls-list
>>>
>> -- 
>> Marco Antoniotti                     
>> http://bioinformatics.nyu.edu/~marcoxa
>> NYU Courant Bioinformatics Group        tel. +1 - 212 - 998 3488
>> 715 Broadway 10th FL                fax. +1 - 212 - 998 3484
>> New York, NY, 10003, U.S.A.
>>
>
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by:
> Tame your development challenges with Apache's Geronimo App Server.  
> Download
> it for free - -and be entered to win a 42" plasma tv or your very own
> Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
> _______________________________________________
> Ecls-list mailing list
> Ecls-list at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ecls-list
>
--
Marco Antoniotti					http://bioinformatics.nyu.edu/~marcoxa
NYU Courant Bioinformatics Group		tel. +1 - 212 - 998 3488
715 Broadway 10th FL				fax. +1 - 212 - 998 3484
New York, NY, 10003, U.S.A.





More information about the ecl-devel mailing list