Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Lisp

Options
  • 30-03-2006 3:47pm
    #1
    Registered Users Posts: 272 ✭✭


    Hi
    I need some help with lisp , i havent a clue how to get iterations going to check/run through a list can anyone give me some simple examples and explanations ....CHEERS:eek:


Comments

  • Registered Users Posts: 1,481 ✭✭✭satchmo


    (I (haven't (used (Lisp))) in ages, ((but it) (seemed (overly))) ((complicated) when) (I (did).))


  • Registered Users Posts: 6,315 ✭✭✭ballooba


    LISP!!! :eek:

    /me jumps out the window.


  • Registered Users Posts: 6,265 ✭✭✭MiCr0


    UCD compsci?


  • Registered Users Posts: 272 ✭✭hannable80


    nah Wit , just cant grasp how to do list itteration findin a value


  • Registered Users Posts: 272 ✭✭hannable80


    nah Wit , just cant grasp how to do list iteration findin a value


  • Advertisement
  • Registered Users Posts: 4,003 ✭✭✭rsynnott


    hannable80 wrote:
    Hi
    I need some help with lisp , i havent a clue how to get iterations going to check/run through a list can anyone give me some simple examples and explanations ....CHEERS:eek:

    Are you trying to perform an operation on each member of the list, or only on some? If each, use mapchar. ( (mapchar myfunction mylist) or similar). If on some, one way would be to do something along the lines of
    (dolist (var list) (and (numberp var) (format t "Element ~S is a number!~%" var)))

    Of course, if you prefer, you could do something more frightening involving recursion and cdr.

    (Edited when I actually tested what I'd written :$)


  • Registered Users Posts: 272 ✭✭hannable80


    Cheers that been a great help can you eplaine the syntax of recursion and cdr....i know all about the cdr , just need to know how to use the recursion


  • Registered Users Posts: 4,003 ✭✭✭rsynnott


    hannable80 wrote:
    Cheers that been a great help can you eplaine the syntax of recursion and cdr....i know all about the cdr , just need to know how to use the recursion

    Recursion in general? Or in LISP. Have you programmed before, or is LISP being used as a starter language?

    A recursive function is one which calls itself, and which knows when to STOP calling itself. The only way recursion in LISP might appear different to in other languages is that in LISP, the result of the last clause in a function is returned; many other languages require explicit return.

    Very simple recursive function in LISP:
    (defun rtest (x)
      (format t "Count: ~S~%" x)
      (and (> x 1)
          (rtest (- x 1))))
    
    ballooba wrote:
    LISP!!! :eek:

    /me jumps out the window.

    Oh, it's not that bad. Prolog's scarier.


  • Registered Users Posts: 272 ✭✭hannable80


    cheers been alot of help.....doin prolog as well , just goin to leave it out when it comes to the summer paper
    Can u explaine "format t "Count: ~S~%""
    the t does not appear in the rest of the code or the function name ?! how is it tied in ?!
    also what is ~S~%?!


  • Registered Users Posts: 4,003 ✭✭✭rsynnott


    hannable80 wrote:
    cheers been alot of help.....doin prolog as well , just goin to leave it out when it comes to the summer paper
    Can u explaine "format t "Count: ~S~%""
    the t does not appear in the rest of the code or the function name ?! how is it tied in ?!
    also what is ~S~%?!

    't' means true. (like 'true' in Java or any non-zero number in C). NIL, broadly speaking, means false. 'format''s first parameter can be a string, in which case it will write to that string, it can be 't', in which case it will write to STDOUT, generally, the console, or it can be 'nil', in which case it returns the string constructed. ~S tells format to consume one symbol from the supplied symbols (in this case var) and print it in its default representation (for a number, this is just the number). ~% means output a newline character appropriate to the platform, and consume no symbols.

    It just occurs to me, are you learning Common Lisp or Scheme? I may have been misleading you... This is Common Lisp.


  • Advertisement
  • Registered Users Posts: 4,003 ✭✭✭rsynnott


    If Common LISP, see if your college library has "Common Lisp: A Gentle Introduction to Symbolic Computation" by David Touretzky. It's old, but it gives a nice introduction to the language, and it's easy to follow.


Advertisement