newLISP Fan Club

Forum => Anything else we might add? => Topic started by: netytan on December 30, 2005, 08:42:14 PM

Title: String to List
Post by: netytan on December 30, 2005, 08:42:14 PM
Hi guys,



I'm using Common Lisp and I'm looking for a way to turn a string into a list of characters. I'm sure there must be a function to do this but I just can't find it :(.



I'm currently working on a sorting function however I'm having a few problems sorting strings in the same function, my hope is to covert the string into characters in order to make sorting easier.



Another idea I'm thinking over is to write my own version of min which will work with other types.



Any tips or examples would be very welcome here :).



Thanks guys,



Mark.
Title:
Post by: Lutz on December 31, 2005, 12:36:26 AM
This forum is about newLISP from http://newlisp.org , which is diffferent from Common Lisp, so the following suggestions may not apply.



In newLISP use 'explode' to turn a string in to a list of characters you could use the built-in function 'sort' to define a 'min' for other types than numbers. See the following interactive session in newLISP:



newLISP v.8.7.1 on OSX, execute 'newlisp -h' for more info.

> (explode "hello")
("h" "e" "l" "l" "o")
> (sort (explode "hello"))
("e" "h" "l" "l" "o")
> (define (my-min s) (first (sort (explode s))))
(lambda (s) (first (sort (explode s))))
> (my-min "world")
"d"
>

Lutz
Title:
Post by: cormullion on December 31, 2005, 09:32:18 AM
It might be confusing that this area of the forum is labelled as "Lisp in general"? A better place to get help might be the comp.lang.lisp newsgroup. And there are plenty of Common Lisp mailing lists (Google tells me).



Mark, an enjoyable read for you, ifi you haven't already seen it, is //http://www.dreamsongs.com/NewFiles/clcrit.pdf, which explains (in a strangely prophetic way) why newLiSP is cool! :-)[/url]
Title:
Post by: netytan on December 31, 2005, 06:30:07 PM
Sorry, I thought that this section was about any Lisp :). I'll refrain from asking such questions in the future.



CL has no (explode) so I've gone ahead and written that, this should allow me to sort strings in the same way I sort nested lists – assuming that I can figure out how to sort nested lists. The sort I've written is actually very simply so the task now about comparing two lists and finding which one comes first.



I'm drawing a blank here so any help would be welcome, any ideas or comments :). Because of the task I'm not able to take advantage of the built-in (sort) so that bit is out :(.



Thanks a lot for the example Lutz it helped more than you know.



I've downloaded the pdf and will read it when I have solved the problem, the reason I decided not to use newLisp originally was because the REPL refuses to work properly on my OSX – when typing code it all has to be on one line, pressing enter causes the form to be executed [usually with errors because the form is incomplete].



Take care guys and thanks again,



Mark.
Title:
Post by: mwg on December 31, 2005, 08:20:23 PM
Maybe the first item here:



http://cl-cookbook.sourceforge.net/strings.html



is what you want.



Regards,

mwg
Title:
Post by: mwg on December 31, 2005, 08:36:12 PM
Oops, with the following:



(defun explode (string1)

      (let* ((character   (string (char string1 0)))

             (new-string  (subseq string1 1))

             (new-length  (length new-string)))

             (cond ((eql new-length 1) (list character new-string))

                  (t   (cons character (explode new-string))))))



...which leads to....



; SLIME: The Superior Lisp Interaction Mode for Emacs



CL-USER> (explode "This a string")

("T" "h" "i" "s" " " "a" " " "s" "t" "r" "i" "n" "g")

CL-USER>



mwg
Title:
Post by: netytan on December 31, 2005, 09:11:25 PM
My common lisp versions of explode & implode:


(defun explode (string)
  (map 'list #'character string))

(defun explode2 (string)
  (coerce string 'list))

(defun implode (object)
  (coerce object 'string))


All of these create character arrays :).



Mark.
Title:
Post by: Ryon on December 31, 2005, 09:13:21 PM
Quote from: "Lutz"This forum is about newLISP from http://newlisp.org

While the main interest of this Fan Club will always be newLISP, we can always discuss other implementations of Lisp. And alternate languages too!



We've talked some about changing the four main headings of this forum, but no consensus has yet been reached. We definitely need to bring in the Mac users who have been banished to the 'General' forum for far too long. But just as soon as that change is made, the hand-held users will feel left out (and the main-framers and the homebrewers too!).



Discussion of alternate ways to solve problems can only be good, and Common Lisp questions will always be welcome here, though I agree with Lutz that they may need a separate topic forum.



Soooo... I'm going to throw this question back to the group. How would you factor the forums to ensure the participation of netytan and all who might show an interest? I'd like to expand the question to welcome discussion from adherents as diverse as: Flatland http://www.geom.uiuc.edu/~banchoff/Flatland/ to Loglan http://www.loglan.org/ .
Title:
Post by: cormullion on January 01, 2006, 02:25:34 PM
Quote from: "Ryon"How would you factor the forums to ensure the participation of netytan and all who might show an interest?


I've seen other forums where there are too many places to post and to keep track of, so the fewer the better. My factoring would be like this:



- newLISP (general discussion, news, etc)

- Windows-specific issues

- Unix-specific issues

- other LISP-related (not newLISP)



I'm happy to post MacOS issues to the Unix forum, if the Linux folks don't mind putting up with me! :-)
Title:
Post by: Lutz on January 01, 2006, 05:29:50 PM
Renaming 'newLISP for LINUX" to "newLISP for UNIX" is a good Idea, because that is what it's really is used for. And most of the time issues discussed there cut across all UNIX versions, and yes OSX is right at home in that group and OSX specific issues are welcome there too.



About the group "LISP in general" it has mostly been used and been understood to be for newLISP issues which are not platform specific, and not to accommodate Common Lisp specific issues. There are other groups and forums on the net better suited for Common Lisp or Scheme topics. But this is just my opinion and I am a guest here like any body else.



Lutz
Title:
Post by: Ryon on January 04, 2006, 08:13:29 PM
That's "Full Member, and Most Appreciated Guest," Lutz!



There is no chance of this site being taken over by any other dialect. I would spin it off into a separate group should that ever occur. And I think that it would be at least entertaining to get some ideas from the LCARS (//http) or INTERCAL (//http) people, should an expert in either wander in to this group.



I've moved some of the general newLISP discussion into the first forum, in order to broaden the field a bit in the last. Good? Bad?



It's certainly easy enough to change. So, let me know!