Jump to content

cond() - why ((t nill)) is common way to end the sublist?


Recommended Posts

Posted

hi

 

(cond
  ((= s "Y") 1) 
  ((= s "y") 1) 
  ((= s "N") 0) 
  ((= s "n") 0) 
  (t nil)
)

 

usually functions return nill when an empty value is issue, in cond returning nill is exposed to the developer...why?

Posted

So why its a common way?(according to docs)

Posted

I think it is just an example to beginners to know the use of t symbol with cond function and nothing's more.

Posted

Is there any use of t byond the self explained true?

Posted
Is there any use of t byond the self explained true?

As far as I know , no.

 

The use of t at the end of cond function is to pass any value you want if the arguments that passed to the function are not to equal to any value.

Posted
Not sure what u mean...

Do you know what is the use of symbol t at the end of cond function?

Posted

As i understand....if t equal to t...than return nill

Posted

Or maybe its a defult if none is true. But why?

Posted

No, if the variable s is not equal to either "Y" "y" "N" "n" the t symbol at the end would give you an option to set the variable ( for example ) to any value you want or print a message to user etc...

Posted

So its a defualt action in case none of the expression is true? So its could be (t (prints "illegel value"). So t is just a trigger in endcof the cond?

Posted

Close , have a look .

 

(cond
  ((= s "Y") 1) 
  ((= s "y") 1) 
  ((= s "N") 0) 
  ((= s "n") 0) 
  (t (alert "Variable (s) in not equal to any of the above check outs "))
)

Posted
Close , have a look .

 

(cond
  ((= s "Y") 1) 
  ((= s "y") 1) 
  ((= s "N") 0) 
  ((= s "n") 0) 
  (t (alert "Variable (s) in not equal to any of the above check outs "))
)

Its not what i meant?

Posted

Put simply, a test expression of 't' will always be validated and so this represents a default condition for when all other conditions are not met; such a condition is by no means necessary, but usually provided by the documentation to help explain how to include a default condition.

 

It looks like you understand this.

Posted

The equivalent in another syntax style could be

 

 

if (s=="Y")

return 1

elseif (s=="y")

return 1

elseif (s=="N")

return 0

elseif (s=="n")

return 0

else

alert( "Variable (s) in not equal to any of the above check outs ")

endif

 

 

Think of (t ....) as being an all-inclusive "else" or "otherwise".

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...