When does the predicate `identifier?` returns `#t` in Racket - racket

I see a predicate identifier? in racket but as the picture bellow shows, it seems to never return the true value.
I went through the docs (here) but it seems there's no info on this particular predicate. does anyone know what's the use of this procedure and when does it return true?

Related

Does #discardableResult actually lead to compiler optimizations?

I have an assignment operation that I want to also return the new value my object is assigned, but only optionally. So of course I would add the #discardableResult attribute. However, does this actually tell the compiler to ignore the return statement inside my function definition if it is not actually being passed anywhere? What optimization does this attribute actually do? All the documentation says is that it "suppresses the warning," although I only want to use it if it can be easily optimized.
Any help is appreciated!

How to ignore a return value in Common Lisp

I'm working with some code which calls ADJUST-ARRAY. I am getting a warning message from the Lisp interpreter (CMUCL) that the return value of ADJUST-ARRAY should not be ignored.
In the code I am working on, ADJUST-ARRAY modifies its argument in place, if I am not mistaken. So it's not necessary to do anything with the return value. Is there a designated way to ignore a return value in Common Lisp? Of course, I could assign the return value to some variable, and then ignore the variable. But that feels clumsy.
I could also assign the return value to the ADJUST-ARRAY argument, something like:
(setq my-array (adjust-array my-array ...))
but that seems to suggest that I'm not sure if ADJUST-ARRAY will modify MY-ARRAY in place.
Any advice is welcome, thanks in advance.
You are correct. As the documentation states:
The result is an array of the same type and rank as array, that is
either the modified array, or a newly created array to which array
can be displaced, and that has the given new-dimensions.
If the result is a newly created array then of course the function would have had no effect on the argument.
Common Lisp almost always require you to use the returned value rather than old bindings in order to have portable code.
The specification of adjust-array is that the adjusted array is the one returned.
What you can expect of the argument array afterwards to be is a bit complicated and may differ between implementations in some cases.
Just use the one returned. You might use setf to modify or let to create a binding.

XMLQUERY() WITHIN XMLATTRIBUTES()

I am doing some basic tasks using, sql/xml. I am currently working on an error message that I get when trying to compute a XMLQUERY() within a XMLATTRIBUTES() function. (See code below)
SELECT XMLELEMENT(NAME "Nodename",
XMLATTRIBUTES(XMLQUERY('$t//Element/text()' PASSING Info AS "t") AS "hello"))
FROM Kurs
The error message that I get, says that there is no qualified routine that can run the function. I cant copy-paste the error message because its in Swedish, but this should be enough.
Also this might help: SQLCODE=-440, SQLSTATE=42884, DRIVER=4.18.60
So my question is (I have been looking for the answer), why doesn't this work? I will always get a value from that XMLQUERY, and it should simply translate into a value and used by XMLATTRIBUTES()
Any documentation, or link, is welcomed as well!
Thank you in advance!
The scalar function XMLQUERY returns an XML value. The function XMLATTRIBUTES expects an expression that returns a value of any type, but XML and some other types.
Thus, the functions are not compatible the way you are using them. DB2 cannot find a routine with that function signature. It results in that error -440.
How about wrapping a CAST/XMLCAST around it...?

What is NSParameterAssert?

What is NSParameterAssert?
Can anyone explain with example?
It is a simple way to test that a method's parameter is not nil or not 0. So basically, you use it to create a precondition, stating that some parameter must be set. If it is not set, the macro causes the application to abort and generates an error on that line. So:
- (void)someMethod:(id)someObjectThatMustNotBeNil
{
// Make sure that someObjectThatMustNotBeNil is really not nil
NSParameterAssert( someObjectThatMustNotBeNil );
// Okay, now do things
}
Pre-conditions are a simple way to ensure that methods/API are being called correctly by the programmer. The idea is that if a programmer violates the precondition, the application terminates early--hopefully during debugging and basic testing.
NSParameterAssert can be used to test that any expression evaluates to be true, however, so you can use it like this as well:
NSParameterAssert( index >= 0 ); // ensure no negative index is supplied
Apple's documentation for the NSParameterAssert() macro

iPhone SDK: Please explain why "nil ==" is different than "== nil"

I have been programming iPhone SDK for around 6 months but am a bit confused about a couple of things...one of which I am asking here:
Why are the following considered different?
if (varOrObject == nil)
{
}
vs
if (nil == varOrObject)
{
}
Coming from a perl background this is confusing to me...
Can someone please explain why one of the two (the second) would be true whereas the first would not if the two routines are placed one after the other within code. varOrObject would not have changed between the two if statements.
There is no specific code this is happening in, just that I have read in a lot of places that the two statements are different, but not why.
Thanks in advance.
They are the same. What you have read is probably talking about if you mistakenly write == as =, the former will assign the value to the variable and the if condition will be false, while the latter would be a compile time error:
if (variable = nil) // assigns nil to variable, not an error.
if (nil = variable) // compile time error
The latter gives you the chance to correct the mistake at compile time.
They might be different if you are using Objective-C++ and you were overriding the '==' operator for the object.
They are exactly the same, it is just a style difference. One would never be true if the other is false.
if it's a recommendation that you use the latter, it's because the second is easier to catch if you accidentally type =. otherwise, they are identical and your book is wrong.
They can only be different if the "==" - Operator is overloaded.
Let's say someone redefines "==" for a list, so that the content of two lists is checked rather than the memory adress (like "equals() in Java). Now the same person could theoretically define that "emptyList == NULL".
Now (emptyList==NULL) would be true but (NULL==emptyList) would still be false.