Stephen Shafer Posted December 1, 2008 Share Posted December 1, 2008 I am trying to get this LISP routine going and I am having an issue adding two variables together. When I run the program it returns ; error: bad argument type: numberp: nil here is the code segment in question fa1 (+ fa1 inc) fa2 (+ fa2 inc) fa1, fa2, and inc are all supposed to be defined as integers and for some reason i keep getting that error and i dont understand why. Basically what is supposed to happen is fa1 gets define as (arbitrarily) 5 and fa2 will be 6, with inc being, say, 7. so basically fa1 and fa2 are both getting "incremented" by 7. Everything else seems to be going smoothly but i cant manage to get this small part to work. Any help is appreciated. Thanks Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 1, 2008 Share Posted December 1, 2008 The error that you are returning seems that there is a variable in your coding that is perhaps defined incorrectly - i.e. as possibly a string. The code that you have posted seems to be correct: (setq fa1 (+ fa1 inc) fa2 (+ fa2 inc) ) ; end setq But if you could post the rest of the LISP you are working on, there may be an error elsewhere. Quote Link to comment Share on other sites More sharing options...
Stephen Shafer Posted December 1, 2008 Author Share Posted December 1, 2008 @Lee Mac Thanks for the input, here's the rest of the code (setq ename (ssname ss index) index (1+ index) Fass (getattval ename "FIBER-ASS") ) (setq Fspl (splstr Fass "-") inc (last Fspl) inc (atoi inc) fa1 (car fspl) fa2 (last fspl) fa1 (+ fa1 inc) fa2 (+ fa2 inc) fa1 (itoa fa1) fa2 (itoa fa2) Fincd (strcat fa1 "-" fa2) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 1, 2008 Share Posted December 1, 2008 I am not sure of the functions "splstr" and "getattval" but maybe I do not know enough... Quote Link to comment Share on other sites More sharing options...
CarlB Posted December 1, 2008 Share Posted December 1, 2008 This code: (setq fa1 (+ fa1 inc) will give you an error if you haven't set fa1 to some value; fa1 is 'nil initially if not set to something, you can't add an increment to nil and thus an error. Yop probably want to set fa1 to 0 initially? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 1, 2008 Share Posted December 1, 2008 ahh good point Carl. But what are the "getattval" and "splstr" ? Do you know? Quote Link to comment Share on other sites More sharing options...
CarlB Posted December 1, 2008 Share Posted December 1, 2008 Don't know, most likely "defuns" (code not shown) that perform tasks of 'getting attribute values' & 'splitting a string' Quote Link to comment Share on other sites More sharing options...
jammie Posted December 1, 2008 Share Posted December 1, 2008 What does the splstr function do to the Fass variable when it is passed through it? Does it split the string and retun it as a list of strings? eg (splstr "100-2-5" "-") returns ("100" "2" "5") Try (setq ename (ssname ss index) index (1+ index) Fass (getattval ename "FIBER-ASS") ) (setq Fspl (splstr Fass "-") inc (last Fspl) inc (atoi inc) fa1 [color="Red"](atoi [/color](car fspl)[color="red"])[/color] ;covert to integer fa2 [color="red"](atoi [/color](last fspl)[color="red"])[/color];covert to integer fa1 (+ fa1 inc) fa2 (+ fa2 inc) fa1 (itoa fa1) fa2 (itoa fa2) Fincd (strcat fa1 "-" fa2) Jammie Quote Link to comment Share on other sites More sharing options...
Stephen Shafer Posted December 1, 2008 Author Share Posted December 1, 2008 getattval gets an attribute value and splstr splits a string based on, in this case, a hyphen and creates a list. @CarlB Is the line fa1 (car fspl) not sufficient enough to properly assign a value to the variable in order to perform the math? @Jammie that seems to work. Well, I mean its returning the correct value now. I just cant manage to get the rest of the routine to work . Anyways, thanks guys Quote Link to comment Share on other sites More sharing options...
CarlB Posted December 2, 2008 Share Posted December 2, 2008 Does (car faspl) return a number? If 'faspl' is a string then (car faspl) wil generate an error. After running the code and it 'errors', check what the value of faspl & fa1 are (and if OK keep checking...) Quote Link to comment Share on other sites More sharing options...
Stephen Shafer Posted December 2, 2008 Author Share Posted December 2, 2008 I think its probably a string Quote Link to comment Share on other sites More sharing options...
Stephen Shafer Posted December 9, 2008 Author Share Posted December 9, 2008 on a seemingly random note. is there a way to write if (0 in lisp? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 9, 2008 Share Posted December 9, 2008 (if (and (> x 0) (< x 10) ) ) Quote Link to comment Share on other sites More sharing options...
CarlB Posted December 9, 2008 Share Posted December 9, 2008 shorter (almost exactly as Stephen posted): (if ( It's often missed that lisp allows more than 2 items in an equality/inequality. For example this is legal (= 1 2 3 4 5) -> nil ( T Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 9, 2008 Share Posted December 9, 2008 Nice one Carl.... i must admit, I didn't realise that more than one item can be used in an equality/inequality - thanks. Quote Link to comment Share on other sites More sharing options...
Stephen Shafer Posted December 9, 2008 Author Share Posted December 9, 2008 Yes, I suppose that what my problem as well. Thanks guys Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.