How to use the built-in function void?. The code
(void? void)
returns #f. Deeply confused.
Appreciate your help. And apparently I have to type more stuff in order to get it posted
void is a function that returns the special constant #<void>. So the function itself is not void, but its result is:
(void? (void))
produces #t. See http://docs.racket-lang.org/guide/void_undefined.html and/or http://docs.racket-lang.org/reference/void.html.
Related
I'm trying to do the most basic string manipulation using Swift. It looks like String provides everything I need, even though it relies on Substring intermediate results. So this works
let myString = "0123456789"
let mySubstring = myString.dropFirst(2)
print(mySubstring.dropLast(2))
It successfully yields "234567" as a Substring.
However, when I attempt to chain the calls...
print(myString.dropFirst(2).dropLast(2))
I get the following error...
9> print(myString.dropFirst(2).dropLast(2))
error: repl.swift:9:7: error: ambiguous use of 'dropFirst'
print(myString.dropFirst(2).dropLast(2))
^
Swift.Collection:39:17: note: found this candidate
public func dropFirst(_ n: Int) -> Self.SubSequence
^
Swift.Sequence:20:17: note: found this candidate
public func dropFirst(_ n: Int) -> AnySequence<Self.Element>
^
So it seems like the compiler is understandably having trouble inferring which dropFirst method to invoke because it is defined twice with different return types.
Is there a way around this? Is this just really poor API design on Apple's part? I'm trying to just get a nice easy to read and concise bit of code. I can also make it work by resorting to NSString but this seems wasteful and even more verbose and obtuse.
UPDATE:
I am able to get a better result by adding as Substring after the chain as in...
print(myString.dropFirst(2).dropLast(2) as Substring)
...since that disambiguates the overloaded methods. I would still love to see a more concise solution. Thanks.
If you define the return type, it has no trouble resolving which function to use. There are a number of ways to do this, such as:
let mySubstring: Substring = myString.dropFirst(2).dropLast(2)
Of course, as you say, you can insert this Substring type within the expression:
let mySubstring = (myString.dropFirst(2) as Substring).dropLast(2)
Surprisingly, it works if you reverse the order and do the dropLast first:
print(myString.dropLast(2).dropFirst(2))
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...?
Is it possible in Matlab to say what the function expects? something like this:
function functionA( obj, uint8(param) )
Here I am saying that the function expects one parameter of type uint8.
Not on the function signature. Typically, you do this via an assert block:
function (obj, param)
assert(isa(param, 'uint8'),...
[mfilename ':invalid_datatype'],...
'Parameter ''param'' must be of class ''uint8''; received ''%s''.',...
class(param));
To complement Rody's answer, there are four ways that you can do this:
Use a conditional and raise an exception if the argument is not of the expected type. The problem with this method is that you have to write a lot of code.
Use an assertion. See Rody's answer or here. One can argue that this is not what assertions are supposed to be used for, but you can certainly use them this way.
Use the validateattributesfunction. See here. This is a very good balance between simplicity and utility. It allows you to check for a number of properties in an argument (and generally, any variable at any part of code)
Use the inputParser class. See here. This is the most powerful method of parsing inputs, but may be overkill. Also, the cost of creating an inputParser object means that it may not be a good idea for functions that are called repeatedly. Nevertheless, it's very good for the public API.
Generically, if I have a function handle (but not the function name), is there a way to see the "help" comment block associated with that function?
Convert the handle to a string with func2str() and call help() on it:
f = #sum;
help(func2str(f))
You might need to regexp() the string, if you have an anonymous function.
First time trying to use Jasmine spies so I hope I'm just missing something obvious. What I want to do is track calls to a function that I have defined as:
window.myFunction = ->
I have a class method that calls this function. The method works fine, and I can test most aspects of it, but the following fails:
beforeEach ->
spyOn(window, 'myFunction').andCallThrough()
it 'should do that thing', ->
MyClass.makesCallToMyFunction
expect(window.myFunction).toHaveBeenCalled()
What am I doing wrong? I've seen plenty of examples on SO and many of them use the spyOn(window, 'myFunction')...expect(window.myFunction) setup/spec.
Any insight is appreciated! Thanks.
This will fail:
it 'should do that thing', ->
MyClass.makesCallToMyFunction
expect(window.myFunction).toHaveBeenCalled()
because MyClass.makesCallToMyFunction is not a method call, that's simply a reference to the makesCallToMyFunction function. If you want to call a CoffeeScript function/method without any arguments then you need to include the parentheses or CoffeeScript won't know that you want to call the function:
MyClass.makesCallToMyFunction()