Jump to content

Type of DEFUN


Sheep

Recommended Posts

19 minutes ago, hanhphuc said:

Wow, never knew that. Thanks, new info for me.


(foreach x '( a b c d e )

(set x nil)

)

 

 

Link to comment
Share on other sites

Quote

(Defun a ()

.....some code

)

Getkword Yes/No

(Defun b ()

...more codes

)

Maybe this question a bit off topic but i cant figure out how to make it. "A" is done and i want and option to continue to "B" or just stop at "A" (and ends the lisp).

1. How do i do that? 

2. Should i reset the vars to nil using (foreach x '(c d e) set nil at defun A or B or both?

Link to comment
Share on other sites

5 minutes ago, Sheep said:

Maybe this question a bit off topic but i cant figure out how to make it. "A" is done and i want and option to continue to "B" or just stop at "A" (and ends the lisp).

1. How do i do that? 

2. Should i reset the vars to nil using (foreach x '(c d e) set nil at defun A or B or both?

 

(Defun a nil

   Some code

   (initget 1 "Yes No")

   (if (eq (getkword "\nProceed to B? [Yes/No]: ") "Yes") (b))

   )

Edited by Jonathan Handojo
  • Thanks 1
Link to comment
Share on other sites

5 minutes ago, Jonathan Handojo said:

 

(Defun a nil

   Some code

   (initget 1 "Yes No")

   (if (eq (getkword "\nProceed to B? [Yes/No]: ") "Yes") (b))

   )

Thanks for your reply. I assume i should set (defun b nil) right?

Link to comment
Share on other sites

6 minutes ago, Sheep said:

Thanks for your reply. I assume i should set (defun b nil) right?

 

Whatever variables you have inside your function b, put those variables to the right of the slash. If you don't have any variables to set, then it's fine to do (defun b nil)

 

For example:

 

(Defun addtwo (a b / c) (setq c (+ a b)))

(Defun testadd nil (addtwo 4 8))

 

Since addtwo has a variable c, you should localize that variable. But testadd doesn't have any variables, so there's nothing to localize.

 

However, if you localize like

 

(Defun testadd ( / addtwo) (addtwo 4 8))

 

The function will fail because there are no functions localized within testadd

  • Thanks 1
Link to comment
Share on other sites

After localized ALL the setq i got:

Quote

; error: bad argument type: numberp: nil

I assume that from localizing ALL the setq's. How to get at that line? Tried inspect but it returns CALLBACK ENTRY (which i have no idea). In Vlide i have set Break ON Error.

Edited by Sheep
Link to comment
Share on other sites

26 minutes ago, Sheep said:

After localized ALL the setq i got:

I assume that from localizing ALL the setq's. How to get at that line? Tried inspect but it returns CALLBACK ENTRY (which i have no idea). In Vlide i have set Break ON Error.

That error indicates that a number is expected as an argument but nil is supplied instead. You'll have to revise your code at where the 'nil' comes from...

 

Or post your code here so we all can help you out.

 

Thanks,

Jonathan Handojo

Link to comment
Share on other sites

2 minutes ago, Jonathan Handojo said:

Or post your code here so we all can help you out.

 

Thanks,

Jonathan Handojo

@Jonathan Handojo, due to the company policies, i can't paste the code to public. If you don't mind, i'll paste it the in private chat.

Link to comment
Share on other sites

2 minutes ago, Sheep said:

@Jonathan Handojo, due to the company policies, i can't paste the code to public. If you don't mind, i'll paste it the in private chat.

Ok, as long as it works out.

Link to comment
Share on other sites

I suppose you can post the code for a moment until I download it, then edit and remove the code.

Link to comment
Share on other sites

None

2 minutes of open window.

7 minutes ago, Jonathan Handojo said:

I suppose you can post the code for a moment until I download it, then edit and remove the code.

 

Edited by Sheep
Code remove due to company policies.
Link to comment
Share on other sites

3 minutes ago, Jonathan Handojo said:

Done...

Please dont paste the whole code when you'are done. My company got several people in this forum so i hope im not in trouble for breaking the rules.

Link to comment
Share on other sites

I recommend you put all your sub functions under the main function. Because you did something like:

 

(defun A (a / b)

  (setq b (* a 5)

  )

 

(defun C nil

  (+ b 9)

  )

 

Since you localised b inside function A, no value is set to the variable b outside that function, therefore C will return the error you encountered.

 

I'd rather you do:

 

(defun A (a / b C d)

  (defun C (e)

    (+ e 9)

    )

  (setq b (* a 5)

        d (C b)

        )

  )

 

P.S. I'm from Indonesia too :) 

 

Thanks,

Jonathan Handojo

Link to comment
Share on other sites

22 minutes ago, Jonathan Handojo said:

I recommend you put all your sub functions under the main function. Because you did something like:

 

(defun A (a / b)

  (setq b (* a 5)

  )

 

(defun C nil

  (+ b 9)

  )

 

Since you localised b inside function A, no value is set to the variable b outside that function, therefore C will return the error you encountered.

 

I'd rather you do:

 

(defun A (a / b C d)

  (defun C (e)

    (+ e 9)

    )

  (setq b (* a 5)

        d (C b)

        )

  )

 

P.S. I'm from Indonesia too :) 

 

Thanks,

Jonathan Handojo

Thank you for your time. I'll try it out once i can figure out which is which. No, im not Indonesian im Malaysian. Close tho, neighbour.

Edited by Sheep
  • Funny 1
Link to comment
Share on other sites

One thing worth noting is that you can also localize your functions too that lies inside a function, hence why I localized C above.

  • Like 1
Link to comment
Share on other sites

Just now, Jonathan Handojo said:

One thing worth noting is that you can also localize your functions too that lies inside a function, hence why I localized C above.

My brain hurts. 10 minutes break.

Link to comment
Share on other sites

On 3/8/2020 at 8:39 AM, Jonathan Handojo said:

 

(Defun a nil

   Some code

   (initget 1 "Yes No")

   (if (eq (getkword "\nProceed to B? [Yes/No]: ") "Yes") (b))

   )

@Jonathan Handojo, i tried above code but if select No, it does not end the LISP. But, if i select Yes, it will goto (defun Proposed) without any problem.

(defun Existing ()
...code
   (initget 1 "Yes No")

   (if (eq (getkword "\nProceed to Proposed? [Yes/No]: ") "Yes") (Proposed))
)


(defun Proposed ()
..code
)

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...