Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
reference a fun from its atom name
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Roberto Ostinelli  
View profile  
 More options Jun 17 2012, 12:11 pm
From: Roberto Ostinelli <robe...@widetag.com>
Date: Sun, 17 Jun 2012 09:11:30 -0700
Local: Sun, Jun 17 2012 12:11 pm
Subject: [erlang-questions] reference a fun from its atom name

Dear list,

is it possible to reference a fun from its atom name? For instance:

1> eunit:test({generator, fun hello_test_/0}).

-> everything is ok.

2> FunName = 'hello_test_/0'.
'hello_test_/0'
3> eunit:test({generator, fun FunName}).
* 1: syntax error before: '}'

Any ideas?

Thank you,

r.

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Uvarov  
View profile  
 More options Jun 17 2012, 1:20 pm
From: Michael Uvarov <free...@gmail.com>
Date: Sun, 17 Jun 2012 21:20:14 +0400
Local: Sun, Jun 17 2012 1:20 pm
Subject: Re: [erlang-questions] reference a fun from its atom name
Use fun M:F/A, where M is a module name, F is a function name and A is arity.
M and F are atoms, A is non_neg_integer,

17> A = 1.
1
18> X = fun lists:reverse/A.
#Fun<lists.reverse.1>
19> X([1,2,3]).
[3,2,1]
_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Uvarov  
View profile  
 More options Jun 17 2012, 1:24 pm
From: Michael Uvarov <free...@gmail.com>
Date: Sun, 17 Jun 2012 21:24:04 +0400
Local: Sun, Jun 17 2012 1:24 pm
Subject: Re: [erlang-questions] reference a fun from its atom name
F = hello_test_, Fun = fun ?MODULE:F/0.
_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tilman Holschuh  
View profile  
 More options Jun 17 2012, 1:40 pm
From: Tilman Holschuh <tilman.holsc...@gmail.com>
Date: Sun, 17 Jun 2012 10:40:32 -0700
Local: Sun, Jun 17 2012 1:40 pm
Subject: Re: [erlang-questions] reference a fun from its atom name
Did you try?

fun() -> apply(?MODULE, hello_test_, []) end.

Cheers
- Tilman

On 2012-06-17, at 9:11 AM, Roberto Ostinelli wrote:

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Zabrane Mickael  
View profile  
 More options Jun 17 2012, 1:44 pm
From: Zabrane Mickael <zabra...@gmail.com>
Date: Sun, 17 Jun 2012 19:44:54 +0200
Local: Sun, Jun 17 2012 1:44 pm
Subject: Re: [erlang-questions] reference a fun from its atom name

fun M:F/A

Sent from my iPhone

Le 17 juin 2012 à 18:11, Roberto Ostinelli <robe...@widetag.com> a écrit :

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roberto Ostinelli  
View profile  
 More options Jun 17 2012, 3:12 pm
From: Roberto Ostinelli <robe...@widetag.com>
Date: Sun, 17 Jun 2012 12:12:03 -0700
Local: Sun, Jun 17 2012 3:12 pm
Subject: Re: [erlang-questions] reference a fun from its atom name

Thank you all, I ended up using this one.

r.

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Samuel  
View profile  
 More options Jun 18 2012, 3:11 am
From: Samuel <samuelri...@gmail.com>
Date: Mon, 18 Jun 2012 09:11:15 +0200
Local: Mon, Jun 18 2012 3:11 am
Subject: Re: [erlang-questions] reference a fun from its atom name

> Thank you all, I ended up using this one.

>> F = hello_test_, Fun = fun ?MODULE:F/0.

Note that this is not exactly what you were trying to do. I guess you
were trying to create a fun to call a local (possibly unexported
function). The construction above creates a fun that does a fully
qualified call (thus, the function must be exported).

Your problem was that instead of a fun you defined an atom:

2> FunName = 'hello_test_/0'.
'hello_test_/0'

Anything enclosed in '' is an atom. What you were trying to do is probably

2> FunName = fun hello_test_/0.

That's the valid syntax to define a fun, and is roughly (not exactly)
equivalent to
2> FunName = fun() -> hello_test() end.

However the first construct will fail in the shell, because you are in
the erl_eval module context there:

2> FunName = fun hello_test_/0.
** exception error: undefined function erl_eval:hello_test_/0

But it will work if you use it in a module that defines hello_test_()

Regards
--
Samuel
_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roberto Ostinelli  
View profile  
 More options Jun 18 2012, 11:04 am
From: Roberto Ostinelli <robe...@widetag.com>
Date: Mon, 18 Jun 2012 08:04:48 -0700
Local: Mon, Jun 18 2012 11:04 am
Subject: Re: [erlang-questions] reference a fun from its atom name

On Monday, June 18, 2012, Samuel wrote:
> > Thank you all, I ended up using this one.

> >> F = hello_test_, Fun = fun ?MODULE:F/0.

> Note that this is not exactly what you were trying to do. I guess you
> were trying to create a fun to call a local (possibly unexported
> function).

no, this is exactly what I wanted to do. I have a function name as an atom
in a variable, and I needed a Fun reference out of it.

Your problem was that instead of a fun you defined an atom:

> 2> FunName = 'hello_test_/0'.
> 'hello_test_/0'

> Anything enclosed in '' is an atom. What you were trying to do is probably

> 2> FunName = fun hello_test_/0.

no, believe it or not but I actually may know the difference between an
atom and a function. no matter how incredible this may sound.

:)

...r.

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »