At just after 2:40 in ShadowofCatron's Scala Tutorial 3 video, it's pointed out that the parentheses following the name of a thunk are optional. "Buh?" said my functional programming brain, since the value of a function and the value it evaluates to when applied are completely different things.
So I wrote the following to try this out. My thought process is described in the comments.
object Main {
var counter: Int = 10
def f(): Int = { counter = counter + 1; counter }
def runThunk(t: () => Int): Int = { t() }
def main(args: Array[String]): Unit = {
val a = f() // I expect this to mean "apply f to no args"
println(a) // and apparently it does
val b = f // I expect this to mean "the value f", a function value
println(b) // but it's the value it evaluates to when applied to no args
println(b) // and the evaluation happens immediately, not in the call
runThunk(b) // This is an error: it's not println doing something funny
runThunk(f) // Not an error: seems to be val doing something funny
}
}
To be clear about the problem, this Scheme program (and the console dump which follows) shows what I expected the Scala program to do.
(define counter (list 10))
(define f (lambda ()
(set-car! counter (+ (car counter) 1))
(car counter)))
(define runThunk (lambda (t) (t)))
(define main (lambda args
(let ((a (f))
(b f))
(display a) (newline)
(display b) (newline)
(display b) (newline)
(runThunk b)
(runThunk f))))
> (main)
11
#<procedure:f>
#<procedure:f>
13
After coming to this site to ask about this, I came across this answer which told me how to fix the above Scala program:
val b = f _ // Hey Scala, I mean f, not f()
But the underscore 'hint' is only needed sometimes. When I call runThunk(f), no hint is required. But when I 'alias' f to b with a val then apply it, it doesn't work: the evaluation happens in the val; and even lazy val works this way, so it's not the point of evaluation causing this behaviour.
That all leaves me with the question:
Why does Scala sometimes automatically apply thunks when evaluating them?
Is it, as I suspect, type inference? And if so, shouldn't a type system stay out of the language's semantics?
Is this a good idea? Do Scala programmers apply thunks rather than refer to their values so much more often that making the parens optional is better overall?
Examples written using Scala 2.8.0RC3, DrScheme 4.0.1 in R5RS.
Hello,
I am returning the variable I am creating in a using statement inside the using statement (sounds funny):
public DataTable foo ()
{
using (DataTable properties = new DataTable())
{
// do something
return properties;
}
}
Will this Dispose the properties variable??
After doing this am still getting this Warning:
Warning 34 CA2000 : Microsoft.Reliability : In method 'test.test', call System.IDisposable.Dispose on object 'properties' before all references to it are out of scope.
Any Ideas?
Thanks
Hi!
What's the best way for me to take url like: http://foobar.com/foo.torrent and check if that really is a torrent, not a html page or something else funny.
Suggestions?
Thank you :)
I've heard that it's possible to mask views with black/white images, where black means fully transparent and white means view is visible. The big difference to clipsToBounds is that the view could be clipped in funny shapes like circles or stars. How could I do that?
Hi, i'm trying to get min-width to work on ie7, funny thing is it works correctly on ie6 using this script http://code.google.com/p/ie7-js/ but it doesn't work on ie7 even with the ie8 or ie9 scripts from the same site, any ideas on how to make this property work on a SELECT input?
thanks in advance.
Everytime I load my model into XNA, I can usually see it far off in the distance. When I change some parameters and make it zoom up close, 10/10 times it's rotated funny and I'm set with the task of rotating it. Is there any easy way to do it except by experimenting? Or am I exporting it wrong (using Blender)? Is there any value I should set the objects in my 3d scene to be before exporting it so they appear 'upright'?
Hi, if I have code like so:
class X extends JFrame
{
X()
{
setLayout(new GridLayout(3,3));
JButton b = new JButton("A-ha");
/*I would like to add this button in the center of this grid (2,2)*/
//How can I do it?
}
};
Thanks.
I'm using textmate for the first time basically, and I am lost as to what keys map to these funny symbols.
using python bundles, what keys do I press for:
run
run with tests
run project unit tests
Also, with textmate, do I actually define a project in textmate or do I just work on the files and textmate doesn't create its own .project type file ?
Hi,
I created one blackberry application which will play a video on a button click.This is my code,
invocation=new Invocation("file:///SDCard/Blackberry/videos/PlayingVideo/funny.mp4");
registry=Registry.getRegistry("net.rim.device.api.content.BlackBerryContentHandler");
try
{
registry.invoke(invocation);
}
catch(Exception e)
{
}
Now i can play the Video file.After clicking the Back button the native player is going to the background.It always running in the background.But i want to close that player.I have no idea about how to do it.Anybody knows please help me.
before somebody screaming RTFM, let me clarify.
does system.totalMemory test the memory used in movie which invokes it, or used by all movies running on the browser/system?
I want to initiate garbage collaction for my app when it reaches a certain limit and i dont want the process to be initialized by the user watching funny cats youtube video.
Following this topic, what is the best (as in witty and/or funny) commit message you have ever encountered?
For example, here's the message for a commit I made a few minutes ago:
This change should have never been made. It kills little children.
NOTE TO SELF: Don't do everything [the boss] tells you immediately.
When using ECMAScripts typeof on plugin elements (i.e. embed or object), Safari & FireFox return "function":
typeof(window.document['myPlugin']) // "function"
This can't be influenced on the plugin side, as the browser doesn't call the plugin here. Funny enough, in IE the same line evaluates to "object".
Is that simply implementation dependent behaviour as per ECMAScript §11.4.3 or am i missing something here?
OK, so we all saw the lists of "funny" or "bad" comments.
However, today, when maintaining an old stored proc, I stumbled upon a comment which I couldn't classify other than "refreshingly brutally honest", left by a previous maintainer around a really freakish (both performance and readability-wise) page-long query:
-- Feel free to optimize this if you can understand what it means
So, in the first (and hopefully only) poll type question in my history of Stack Overflow, I'd like to hear some other "refreshingly brutally honest" code comments you encountered or written.
Hi,
I created one blackberry application which will play a video on a button click.This is my code,
invocation=new Invocation("file:///SDCard/Blackberry/videos/PlayingVideo/funny.mp4");
registry=Registry.getRegistry("net.rim.device.api.content.BlackBerryContentHandler");
try
{
registry.invoke(invocation);
}
catch(Exception e)
{
}
Now i can play the Video file.After clicking the Back button the native player is going to the background.It always running in the background.But i want to close that player.I have no idea about how to do it.Anybody knows please help me.
Hi,
I had installed a new IIS7 on a Win2008. Everything worked perfect on the server, but everytime a computer in the LAN tried to browse the web server the client got an error
401 - No autorizado: acceso denegado debido a credenciales no válidas.
No tiene permiso para ver este directorio o esta página con las credenciales que ha proporcionando.
The IIS user had full permission in the fily system and on the IIS.
Have anyone an idea why this could be happening?
Thanks
I'd like to write a bot to play in the 3D RoboCup simulated soccer league. Can anyone point me at some code that already deals with communication with the server, etc?
Ideally this would be .NET code, but an example produced in any language would still be useful.
EDIT For anyone who is not familiar with the RoboCup 3D Soccer league, check out this YouTube video. It has some pretty funny moments, if you're into that sort of thing...
Hello,
I know how to capture video on android device, but i would like to capture video and add some other information on it e.g. some funny timeclock and save it all to file so the person watching the video will see the exact time of capturing. I would also like to add some watermark.
Do you know how can i do it or is it possible on android device? I read the API but couldnt find anything that could help me.
Whenever, working on a big project. Using Technical names for your class can be pretty harsh on yourself to remember.
So, what are the coolest class name that you can think of which is descriptive, funny and easy to remember.
PS also include parent and class names just to add a little spice
Hi, this is my question...
I have a compilation(UITableView) of videos from youtube of a particular gender(funny videos, for example) and I want to know if this app will pass the approval process.
These videos are freely accessible by anyone in youtube, but ins't uploaded/recorded by me.
This is a concept:
http://img263.imageshack.us/img263/3466/img0075.png
(obviously with a cool skin design and more options like Favorites, Share with friends, etc)
Thanks for reading.
Hi,
I created one blackberry application which will play a video on a button click.This is my code,
invocation=new Invocation("file:///SDCard/Blackberry/videos/PlayingVideo/funny.mp4");
registry=Registry.getRegistry("net.rim.device.api.content.BlackBerryContentHandler");
try
{
registry.invoke(invocation);
}
catch(Exception e)
{
}
Now i can play the Video file.After clicking the Back button the native player is going to the background.It always running in the background.But i want to close that player.I have no idea about how to do it.Anybody knows please help me.
Hi,
I have finally managed to get javan-whenever gem working on my site5 server, and updating the crontab is quite easy, however whenever a cron job is run with the code that is generated, i get a "missing required gems" error where it lists about 8/10 of my gems.
Has anyone else had this problem? If so, what would the solution be.
The funny thing is that when it outputs where my gems are, this is all correct, and the gems are loading fine from within my application.
Cheers,
Matenia
Is there any good framework for comparing whole objects?
now i do
assertEquals("[email protected]", obj.email);
assertEquals("5", obj.shop);
if bad email is returned i never get to know if it had the right shop, i would like to get a list of incorrect fields.
I was trying pick a name for an interface through which I can pass something into an object like:
If the object is INeedX then SetX(some x) method will be called;
If the object is INeedY then SetY(some y) method will be called;
and so on. (funny as hell, I know :) )
I try to find a different name for this kind of interfaces but I can't figure this out.
Does anybody have an idea how to name the INeedSomething interface ?
I have 300 boolean fields in one table, and im trying to do somithing like that:
One string field:
10000010000100100100100100010001
Ha a simple way to do a simple search os this field like:
select * from table where field xor "10000010000100100100000000010001"
Im tring this but is to long:
select * from teste where mid(info,2,1) and mid(info,3,1)
:) Help!!