Graal Forums  

Go Back   Graal Forums > Development Forums > Future Improvements
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11-29-2009, 09:07 PM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Function Closures

Inline Closures
These would be useful to make code a bit cleaner:
Graal Script Code:

foobar
(function (temp.atemp.b) {
  return 
temp.temp.b;
}); 

In-place Execution
This would be useful for proper scoping (since we don't have block scope):
Graal Script Code:

temp
.= function () {
  
temp.foo 3;
  
temp.bar 50;
  
temp.baz 4;
  return 
temp.foo temp.bar temp.baz;
}(); 
Reply With Quote
  #2  
Old 12-12-2009, 12:52 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Another cool thing would be binding variables to the closure during creation:
Graal Script Code:
function foo() {
  
temp.2;
  
temp.= function (temp.xtemp.y) use (temp.a) {
    return (
temp.temp.y) * temp.a;
  };
  
this.bar(temp.f3);
}

function 
bar(temp.ctemp.d) {
  echo(
temp.c(4temp.d)); // would echo 14

Reply With Quote
  #3  
Old 12-12-2009, 01:21 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Quote:
Originally Posted by WhiteDragon View Post
Inline Closures
These would be useful to make code a bit cleaner:
Graal Script Code:

foobar
(function (temp.atemp.b) {
  return 
temp.temp.b;
}); 
You mean instead of doing this?
Graal Script Code:
temp.func = function (temp.atemp.b) {
  return 
temp.temp.b;
};
foobar(temp.func); 
Reply With Quote
  #4  
Old 12-12-2009, 01:30 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by Admins View Post
You mean instead of doing this?
Graal Script Code:
temp.func = function (temp.atemp.b) {
  return 
temp.temp.b;
};
foobar(temp.func); 
Yes.

In a script where I created 40 to 50 different closures it was getting irritating to create a junk variable like that.
Reply With Quote
  #5  
Old 12-12-2009, 01:51 AM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by WhiteDragon View Post
Yes.

In a script where I created 40 to 50 different closures it was getting irritating to create a junk variable like that.
It is not really a junk variable because when you define a function normally, you are still creating a variable which contains the function object without realising it. In any other case, what other language uses that kind of syntax that you suggested? It is horrendously ugly.
__________________
Skyld
Reply With Quote
  #6  
Old 12-12-2009, 02:31 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by Skyld View Post
It is not really a junk variable because when you define a function normally, you are still creating a variable which contains the function object without realising it.
It is a junk variable because I create it, and only use it one time.

Quote:
Originally Posted by Skyld View Post
In any other case, what other language uses that kind of syntax that you suggested?
Any C-like language with support for closures/anonymous functions. Try ECMAScript (JavaScript, ActionScript, QtScript, Objective-J), or PHP.

All the functional languages such as Haskell, Erlang, LISP, and Scheme also allow defining the function inline, so the concept is not bogus either.
Reply With Quote
  #7  
Old 12-12-2009, 02:09 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by WhiteDragon View Post
It is a junk variable because I create it, and only use it one time.
Maybe you could reuse it for the next time you need an anonymous function!!

Quote:
Any C-like language with support for closures/anonymous functions. Try ECMAScript (JavaScript, ActionScript, QtScript, Objective-J), or PHP.
Man, I want to agree with this thread on principle, but after you calling PHP C-like, I really just want to punch you in the face with a monoid in the category of endofunctors.

Worth adding that lua has the almost the same syntax except without the curly braces because not having curly braces there is what lua does, C# has almost the same syntax except with delegate instead of closure because calling something anonymous a function scares OOP programmers, etc. Perl has the same kind of feature except without a parameter list and yet another keyword.

Quote:
All the functional languages such as Haskell, Erlang, LISP, and Scheme also allow defining the function inline, so the concept is not bogus either.
With GS2 basically looking like Javascript, that is the only comparison there is. If people feel that adding Javascript's syntax for anonymous functions is not worth it, comparing to even crazier languages is not going to help, I suspect.
Reply With Quote
  #8  
Old 01-30-2010, 02:22 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Bump.

This could be used on the iPhone too!
Reply With Quote
  #9  
Old 01-30-2010, 02:39 AM
12171217 12171217 is offline
Banned
Join Date: Jan 2009
Posts: 453
12171217 has a spectacular aura about
Quote:
Originally Posted by WhiteDragon View Post
This could be used on the iPhone too!
so?
Reply With Quote
  #10  
Old 01-30-2010, 03:03 AM
Immolate Immolate is offline
Indigo
Join Date: Dec 2009
Posts: 322
Immolate is on a distinguished road
I'd like this to be added in but I can't see where average scripters would use it, so putting my self in Stefan's shoes, it'd probably never implemented or really low priority.
Reply With Quote
  #11  
Old 01-30-2010, 05:38 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Quote:
Originally Posted by 12171217 View Post
so?
It's the only way to get something done by Stefan these days, it seems.
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #12  
Old 01-30-2010, 07:52 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Quote:
Originally Posted by coreys View Post
It's the only way to get something done by Stefan these days, it seems.
Certainly making comments like this will help!
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:33 AM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright (C) 1998-2008 Linux cyberjoueurs All Rights Reserved.