Lisp Learning syntax error

Lisp Learning syntax error

GeryKnee
Advocate Advocate
653 Views
7 Replies
Message 1 of 8

Lisp Learning syntax error

GeryKnee
Advocate
Advocate

 

The following runs errorly


(defun c:xx ( / )
(Setq p0 nil)
(if (setq pt (getpoint "\nSpecify point: "))
(Progn ;;true
(setq i1 0)
if( (or (= i1 0) (/= ptHt p0) )
(Progn ;;true
(setq i1 1)
(setq p0 ptHt)
(princ 1)
);;Progn true
(Progn ;;false
(princ 2)
);;Progn false
);;if
);;Progn true
(Progn ;;false
(setq i2 0)
);;Progn false
);;if
(princ)
)

 

Running it i get

 


Command: xx
Specify point: 12; error: no function definition: nil
Command:

 

maybe is something simple

I think i have a large road to catch lisp knowledge

Gery

0 Likes
Accepted solutions (1)
654 Views
7 Replies
Replies (7)
Message 2 of 8

annoisscary
Advocate
Advocate
Accepted solution

I believe its this line here

 

 

 

if( (or (= i1 0) (/= ptHt p0) )

 

 

This should fix it

 

(defun c:xx ( / )
(Setq p0 nil)
(if (setq pt (getpoint "\nSpecify point: "))
(Progn ;;true
(setq i1 0)
(if (or (= i1 0) (/= ptHt p0) )
(Progn ;;true
(setq i1 1)
(setq p0 ptHt)
(princ 1)
);;Progn true
(Progn ;;false
(princ 2)
);;Progn false
);;if
);;Progn true
(Progn ;;false
(setq i2 0)
);;Progn false
);;if
(princ)
)

 

 

 

And again, all I did was correct the typos on the one line to read:

 

 

(if (or (= i1 0) (/= ptHt p0) )

 

 

 

 

  

Message 3 of 8

GeryKnee
Advocate
Advocate

Sorry

 

ptHt is Pt

 

:::

 


(defun c:x2 ( / )
(Setq p0 nil)
(if (setq pt (getpoint "\nSpecify point: "))
(Progn ;;true
(setq i1 0)
if( (or (= i1 0) (/= pt p0) )
(Progn ;;true
(setq i1 1)
(setq p0 pt)
(princ 1)
);;Progn true
(Progn ;;false
(princ 2)
);;Progn false
);;if
);;Progn true
(Progn ;;false
(setq i2 0)
);;Progn false
);;if
(princ)
)

 

Does the same

 

0 Likes
Message 4 of 8

annoisscary
Advocate
Advocate

Again, same typo. its this line,

if( (or (= i1 0) (/= pt p0) )

;Needs to be,
(if(or(= i1 0)(/= pt p0))

 

0 Likes
Message 5 of 8

calderg1000
Mentor
Mentor

Regards @GeryKnee 

It's worth the try, soon you will surely be coding better. Nested Ifa can get a bit confusing.

Although it is not very clear what you are trying to do, but I have tried to interpret your code a bit and verify that there are some lines that are not going to be executed. Because your first conditional will always be true, and the result will be equal to 1

(defun c:x2 (/ )
  (Setq p0 nil)
  (if (setq pt (getpoint "\nSpecify point: "));;;here you must enter a condition that evaluates: true false
    (Progn ;;true
           (setq i1 0)
;;;if( (or (= i1 0) (/= pt p0) );;a parenthesis is missing here
           (if (or (= i1 0) (/= pt p0)) ;;This condition will always be true, therefore the other lines will not be evaluated.
             (Progn ;;true
                    (setq i1 1)
                    (setq p0 pt)
                    (princ 1)
             )
             ;;Progn true
;;;-----------------------------will never be evaluated
             (Progn ;;false
                    (princ 2)
             ) ;;Progn false
           );;if
;;;-----------------------------will never be evaluated
    );;End Progn true
    (Progn ;;false
           (setq i2 0)
    );;Progn false
  );;if
;;;-----------------------------will never be evaluated
  (princ)
)

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes
Message 6 of 8

GeryKnee
Advocate
Advocate

 

Thank You Sir

I saw that the prpblem was that i started a code προταση without using "( " on start.

That's because i write codes in pascal.

I found an online list compiler :

https://www.tutorialspoint.com/execute_lisp_online.php

but i wasn't able to use it

Maybe i must try again to do it.

Thanks,

Gery

 

 

0 Likes
Message 7 of 8

calderg1000
Mentor
Mentor

Dear @GeryKnee 

To code interactively, you have the visual lisp editor and as of 2021, VSCode

Here you have information

https://knowledge.autodesk.com/es/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2021/ESP/Au...


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes
Message 8 of 8

Sea-Haven
Mentor
Mentor

Notepad++ has a run code from current file, did use it all the time and as I have said before has bracket checking.

 

 

 

I write most code not spaced but i think for you may be worthwhile to make it easier to see where stuff starts and finishes. This is notepad++ note the red brackets doing auto checking. Just put mouse on bracket and opposite end will be shown.

 

SeaHaven_0-1666500323443.png

 

0 Likes