Author Topic: ELM ----Is this correct?  (Read 2582 times)

0 Members and 1 Guest are viewing this topic.

Jeff H

  • Needs a day job
  • Posts: 6150
ELM ----Is this correct?
« on: April 26, 2011, 07:28:01 PM »
I do not know if any of you have ran across this site http://art2.ph-freiburg.de/Lisp-Course      (to register you put in username and password in login area)
It's a basic beginners course to LISP

It checks your answers to see if they are correct, but I do not know if I am making functions that give correct answer but are poorly designed.

So here is the last one I did
Quote
MONOTON-ANSTEIGEND-P
Define a recursive predicate MONOTONIC-INCREASING-P, that has a number list as its argument. That predicate should test whether the numbers in the number list are in monotonic increasing order. This being the case, T is returned, otherwise NIL.

Examples:

(MONOTONIC-INCREASING-P '(1 2 5 7 9))
T
(MONOTONIC-INCREASING-P '(1 2 5 5 9 9))
T
(MONOTONIC-INCREASING-P '(1 2 5 3 9))
NIL
(MONOTONIC-INCREASING-P '())
T


Answer that was evaluated as correct
Is this Lispy?
Code: [Select]
(DEFUN MONOTON-ANSTEIGEND-P (NUMBERLIST)
   (COND
   ((ENDP NUMBERLIST) T)
   ((ENDP (REST NUMBERLIST)) T)
   ((> (FIRST NUMBERLIST)(SECOND NUMBERLIST)) NIL)
   (T (MONOTON-ANSTEIGEND-P (REST NUMBERLIST)))))


If anyone is a beginner and interested in doing some chapters maybe we could compare answers.

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: ELM ----Is this correct?
« Reply #1 on: April 26, 2011, 07:31:59 PM »
Bear in mind that there are various dialects of LISP - AutoCAD uses AutoLISP.  Your code looks like Common LISP.

In AutoLISP it could be:

Code: [Select]
(defun MONOTONIC-INCREASING-P ( l )
  (if (cadr l)
    (if (<= (car l) (cadr l))
      (MONOTONIC-INCREASING-P (cdr l))
    )
    t
  )
)

Or

Code: [Select]
(defun MONOTONIC-INCREASING-P ( l )
  (cond
    ( (not (cadr l)) )
    ( (<= (car l) (cadr l)) (MONOTONIC-INCREASING-P (cdr l)))
  )
)

Or

Code: [Select]
(defun MONOTONIC-INCREASING-P ( l )
  (or (not (cadr l)) (and (<= (car l) (cadr l)) (MONOTONIC-INCREASING-P (cdr l))))
)
« Last Edit: April 26, 2011, 07:41:11 PM by Lee Mac »

Jeff H

  • Needs a day job
  • Posts: 6150
Re: ELM ----Is this correct?
« Reply #2 on: April 26, 2011, 07:58:41 PM »
Bear in mind that there are various dialects of LISP - AutoCAD uses AutoLISP. Your code looks like Common LISP.

Thanks Lee,
I thought it would still use same concept which is all that matters.

I was follwing their style but I like your implamentation's better.

I tested one and said it was wrong although used in the evaluation window it produced correct answer for all test case's which is confirming that correct answer must match their implamentation.

Would this fail given a list with 1 item
Code: [Select]
(defun MONOTONIC-INCREASING-P ( l )
  (cond
    ( (not (cadr l)) )
    ( (<= (car l) (cadr l)) (MONOTONIC-INCREASING-P (cdr l)))
  )
)

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: ELM ----Is this correct?
« Reply #3 on: April 26, 2011, 08:07:33 PM »
Bear in mind that there are various dialects of LISP - AutoCAD uses AutoLISP. Your code looks like Common LISP.

Thanks Lee,
I thought it would still use same concept which is all that matters.

Same concept, different syntax. Bear in mind there are some functions in Common LISP which don't exist in AutoLISP and vice-versa.

Would this fail given a list with 1 item

Depends whether you want a single item list to return T or nil   :roll:  I vote it should return T

Jeff H

  • Needs a day job
  • Posts: 6150
Re: ELM ----Is this correct?
« Reply #4 on: April 26, 2011, 08:28:53 PM »
I was looking at that site because I have quickly looked over AutoLisp tutorials and have not seen good explanations of it at a lower level.

To me it makes it easier to understand how it works a little deeper and that site started to look promising but has got into the style of 'If given A just remember do B'
instead of 'If given A here is why B and this is why C fails......etc'

but the bigger question I am asking myself is why have I not just realized I am surrounded by Lisp pro's and just ask the questions here.

I guess I am doing the normal learning stages in getting academic style knowledge and then have 'real-world' experts relearn you the correct way.


So instead of this great site teaching me that every COND first terminating case should check for empty list
just ask one of you 'real-world programers' who write code that actually is used in solving real life problems

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ELM ----Is this correct?
« Reply #5 on: April 26, 2011, 11:16:44 PM »
Well I hope you considered these too:
-----------------------------------------------
-----------  Programing References  ------------
-----------------------------------------------

http://www.autodesk.com/techpubs/autocad/acad2000/dxf/index.htm   DXF Codes

http://www.analogx.com/contents/articles/howtoprg.htm  So you want to be a Programmer...
http://pages.cs.wisc.edu/~vernon/cs367/notes/6.RECURSION.html  Recursion
http://jefferypsanders.com/autolisp.html
http://www.geocities.com/siliconvalley/2151/matrices.html


Volume 1 of The Art of Computer Programming
http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html#%_toc_start    CONTENTS
http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-38.html#%_index_start    INDEX




--------------  Links by CAB  -----------------
http://www.theswamp.org/index.php?topic=26955.msg326759#msg326759

To get off the ground in a hurry you should read from these sites:
http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%202010%20User%20Documentation/files/WS73099cc142f48755-381799d411f6fb5af15-62c4.htm

Start at the beginning   http://www.afralisp.net/

http://jefferypsanders.com/autolisp.html
http://ronleigh.info/autolisp/index.htm
http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=770225
http://sites.google.com/site/skatterbrainz/vldb

Intermediate to Advanced:
http://pages.cs.wisc.edu/~vernon/cs367/notes/6.RECURSION.html



Advanced:
http://www.atablex.com/htmls/excel-bible.htm

The Visual LISP Developer's Bible (eBook)   [***  Get this ***]
http://carnet-de-cablage.chez-alice.fr/Doc/lakose_The_Visual_LISP_Developers_Bible.pdf

http://www.caddigest.com/subjects/autocad/tutorials/select/parsai_vlx.htm


References:
http://www.hyperpics.com/commands/index.asp
http://www.autodesk.com/techpubs/autocad/acad2000/dxf/


Extra credit:
http://www.analogx.com/contents/articles/howtoprg.htm
http://www.paulgraham.com/progbot.html
http://www.dreamsongs.com/SeatBelts.html
http://www.dreamsongs.com/ArtOfLisp.html

I found these links too but have not explored them.

Link to pdf Lessons:
http://forums.augi.com/showpost.php?p=190406&postcount=21

14 lessons by Dave Pitzer
http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=2309147
follow the link at the bottom of each lesson

Free AutoLisp course
http://forums.augi.com/attachment.php?attachmentid=3425&d=1093637254

Computer Science 50: Introduction to Computer Science I Harvard College
http://cs50.tv/


http://www.asmitools.com/Files/Programs.html
http://www.asmitools.com/Files/Tutorials.html


http://www.softwarepreservation.org/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf
http://carnet-de-cablage.chez-alice.fr/Doc/lakose_The_Visual_LISP_Developers_Bible.pdf
http://augiru.augi.com/content/library/au07/data/paper/CP311-4.pdf
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: ELM ----Is this correct?
« Reply #6 on: April 27, 2011, 12:28:43 AM »
Thanks CAB will look through them.