Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - netytan

#1
Hey all,



I'm wondering who created NewLisp, was it a team of people or someone in particular I could converse with about the internals of a Lisp interpreter, assuming thats not too much of a hassle :). If anyone knows of a way I could get in touch with said creator could you let me know please.



Thanks



Mark.
#2
Anything else we might add? /
January 14, 2006, 02:13:10 PM
Thanks eddie I looked in the wrong folder, I was looking in mzlib. I wouldn't know where this would be located on windows either not being a windows user ;). At a guess I'd say in the same dir structure under whatever location you installed it?



The second argument must be the subdir to load the file from but whats the trailing "1" for?



Thanks again eddie,



Enjoy all!



Mark.
#3
Anything else we might add? /
January 12, 2006, 01:38:53 PM
Thanks for all your posts guys they helped a lot, just having similar Lisp code to read lets me find new techniques to use :).



Eddie: Scheme, including Dr. Scheme doesn't have those functions in list.ss, filter is available although it uses some tricks because of weaknesses in the implementation (according to one comment).



If you have them in your version could you please most the code for reduce?



I really enjoy Scheme, it's clean and minimal and there are a lot of different tools for it, named let is way better than the CL labels which ends up looking messy no matter what you do :(.



I agree with you about the long names however one of the joys of Lisp is that you can always change it, if you don't like the long names give them another, or write a macro to do things your way :D.



Lutz: tail-recursion is very functional, using iterative styling you'd more likely use a lot of set!'s where this way everything kind of flows, or thats how i see it anyway.



Iteration does make some things simpler but then we have map etc. to accomplish these things too. I just find recursion to be interesting, I haven't used it a lot in the past so it's a challenge.



Heres what I came up with in the end, it's not dissimilar to either of yours :D. There are a few good examples of tail-recursion I've seen around the web, if i find any good ones again I'll post a link for you but wikipedia has a nice explanation of what happens :).


(define filter
  (lambda (fn values)
    "This function is a tail recursive implementation of the filter
    function found in other Lisp dialect."
    (let loop ((v values)
               (rest '()))

      ;;; If there are items in v then CAR and CDR are saved; return
      ;;; rest after reversing.
      ;;;
      ;;;   Checks if fn  => #t  -> add item to rest & repeat.
      ;;;                 => #f  -> loop without adding item.
      (if (pair? v)
        (let ((item (car v))
              (next (cdr v)))
          (if (fn item)
            (loop next (cons item rest))
            (loop next rest)))
          (reverse rest)))))


Thanks again,



Mark.
#4
I don't know if anyone here uses Scheme but Scheme doesn't include a reduce or filter function, so I set about writing some for fun and in any case it's a good way to learn :).


(define filter
  (lambda (fn values)
    "This function is a tail recursive implementation of the filter function
    found in other Lisp dialect."
    (let loop ((v values)
               (rest '()))
     
      (let ((item (car v))
            (next (cdr v)))               ; Saves car and cdr for efficiency.

        (if (fn item)
          ;; Add the current 'item to 'rest if 'fn returned #t, then continue
          ;; though the list. Return 'this AND 'rest revsered.
          (if (pair? next)
            (loop next (cons item rest))
            (reverse (cons item rest)))
           
          ;; Don't add the 'item to the 'rest list but continue on though the
          ;; list.
          (if (pair? next)
            (loop next rest)
            (reverse rest)))))))


> (filter even? '(1 2 3 4 5 6 7))
(2 4 6)


The function is tail-recursive, which happy about but I wonder if it can be done in a better way in any Lisp dialect (inc. newLisp). My intend here was to gain more experience with recursive techniques so that's the only limit there, I know I could do it with map but that's not what I want here :).



Any tips or insight you could give would be more welcome than you know.



I'm currently thinking about how to do reduce but I'm not so sure how it works to he honest, it's not something I've used much before recently.



EDIT: Please forgive the text-wrapping on the comments.



Thanks in advance,



Mark.
#5
Anything else we might add? / Some help: comparing lists
December 31, 2005, 11:32:03 PM
Hey all,



If you've seen my previous thread you'll know that I'm working on a sort program just for fun, I'm new to lisp and I thought it'd be a nice way to get to know it [by setting little tasks].



As part of this I need to be able to compare Lists of items and decide which comes first. This is proving to be harder than I thought it would be, I have my sorting program up to the point that I can express the way items are compared but have no idea how to do this on lists.



Could someone maybe give me an example involving comparing two lists. For obvious reasons this can't include the built-in function (sort).



I'm using CL but it shouldn't be a problem converting between the two so please post some examples.



Thanks,



Mark.
#6
Anything else we might add? /
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.
#7
Anything else we might add? /
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.
#8
Anything else we might add? / String to List
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.
#9
Anything else we might add? / Recusion
December 16, 2005, 09:24:19 AM
I'm having some real problems wrapping my head around recursion, kinda embarrassing but hey. I was hoping someone would have some good advice here :).



Mark.
#10
Anything else we might add? /
December 10, 2005, 05:51:38 AM
Oh ok, so even symbols are atoms in Lisp? Lisp in general not just NewLisp



Thanks Lutz,



Mark.
#11
Anything else we might add? / Atoms Symbols etc
December 09, 2005, 05:44:35 PM
I was wondering if somone could tell me what an atom and what an Symbol is, they seem to be used intemitently and I just can't figure it out. I assumed that a Sybol was like a variable but an Atom I have no idea, is a Cons an Atom?



Thanks a lot guys :),



Mark.
#12
Anything else we might add? /
December 08, 2005, 09:58:59 AM
Wow ok, crazy guys. I spent two years with Python and Lisp is simply better. I dont know it as well yet but I have to say it seems a little odd to me. Still, they have a valid point about there not being as much documentation or example code. Thats not the point... but then, would also choose ASM over C anyday.



Maybe it's just me but I think they should have stuck with Lisp.



Mark.
#13
Anything else we might add? /
December 06, 2005, 04:43:53 PM
Lol yes :) tried that code right at the beginning however Scheme is a little bitch in this sense and you have to make sure that what your trying to append is also a list it throws.



The one I'm using right now simply does a (cons) to collect all of the results in positive-binary; i imagine negative-binary will do the same. I have this nice little function which does a conditional function call and reverses the results before returning.



(define binary
  (lambda (number)
    "This function provides a simple generic front end to our
    positive/negative binary functions."
    (reverse
      ((if (> number 0)
        positive-binary
        negative-binary) number))))


As always please feel free to criticize I could really use any suggestions you guys could give while I'm getting to grips with Lisp :).



Very tidy in NewLisp. How does NewLisp compare for performance with Scheme and CL guys?
#14
Anything else we might add? /
December 06, 2005, 03:49:19 PM
Oh, really liked the advice about how you should write in the language you wish you had :). Haven't heard it put quite like that.



Mark.
#15
Anything else we might add? /
December 06, 2005, 03:44:05 PM
Thanks so much, thats just what I needed. However I was wondering if this would not better be implemented as a Macro, I'm not sure how NewLisps support for Macros is but Schemes really suck, it seems like very paper that talks about them and how to utilize them just doesn't work :(.



Just curious,



Thanks again :),



Mark.