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
serializing functions
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
  4 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
 
damien morton  
View profile  
 More options Nov 16 2008, 4:21 pm
From: "damien morton" <dmor...@bitfurnace.com>
Date: Mon, 17 Nov 2008 08:21:42 +1100
Local: Sun, Nov 16 2008 4:21 pm
Subject: [erlang-questions] serializing functions

If I take the most basic of functions, e.g. fun()->0 end. and serialize it
using term_to_binary(), it seems that this function is serialized to 650
bytes.
I guess I was wondering if its better to send a Mod:Fun pair from one node
to another, or to send an actual function() object. Now, I am still not sure
if a function() can be sent over the wire, but a Mod:Fun pair sure is a
whole lot more compact.

What are the normal best practices when handling functions that might be
send over the wire? Prefer Mod:Fun over function()?


 
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.
Richard Carlsson  
View profile  
 More options Nov 16 2008, 4:59 pm
From: Richard Carlsson <richa...@it.uu.se>
Date: Sun, 16 Nov 2008 22:59:06 +0100
Local: Sun, Nov 16 2008 4:59 pm
Subject: Re: [erlang-questions] serializing functions

damien morton wrote:
> If I take the most basic of functions, e.g. fun()->0 end. and serialize
> it using term_to_binary(), it seems that this function is serialized to
> 650 bytes.

If you write "fun ... end" in the shell, you will get a rather
peculiar closure that actually contains the abstract syntax tree
for the fun-expression (which will be interpreted by erl_eval
when the closure is applied). That's why it's rather big.

> I guess I was wondering if its better to send a Mod:Fun pair from one
> node to another, or to send an actual function() object. Now, I am still
> not sure if a function() can be sent over the wire, but a Mod:Fun pair
> sure is a whole lot more compact.

> What are the normal best practices when handling functions that might be
> send over the wire? Prefer Mod:Fun over function()?

To have a module send one of its anonymous funs to another node will
work (and won't be larger than the size of any captured variables
plus a few additional words to identify the fun), but it requires
that the code (for the module in which the fun is written) on both
nodes is exactly the same.

You can have the best of two worlds by sending e.g. "fun foo:bar/0",
which has a compact encoding and always calls the latest version of
module foo, but is still a fun-object that you can apply as F().

    /Richard

--
 "Having users is like optimization: the wise course is to delay it."
   -- Paul Graham


 
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.
Matthias Lang  
View profile  
 More options Nov 16 2008, 5:10 pm
From: Matthias Lang <matth...@corelatus.se>
Date: Sun, 16 Nov 2008 23:10:54 +0100
Local: Sun, Nov 16 2008 5:10 pm
Subject: Re: [erlang-questions] serializing functions

On Monday, November 17, damien morton wrote:
> If I take the most basic of functions, e.g. fun()->0 end. and serialize it
> using term_to_binary(), it seems that this function is serialized to 650
> bytes.

I'd guess you concluded that after trying it in the shell, not a
module. IIRC, funs made in the shell are special, they carry around
a complete (?) representation of the fun.

> I guess I was wondering if its better to send a Mod:Fun pair from one node
> to another, or to send an actual function() object.

In general, sending the module and the function name is not equivalent
to sending a fun.

> Now, I am still not sure if a function() can be sent over the wire,
> but a Mod:Fun pair sure is a whole lot more compact.
> What are the normal best practices when handling functions that might be
> send over the wire? Prefer Mod:Fun over function()?

The gotchas I can think of are related to code loading.

Matt


 
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.
mats cronqvist  
View profile  
 More options Nov 19 2008, 5:45 pm
From: mats cronqvist <ma...@kreditor.se>
Date: Wed, 19 Nov 2008 23:45:23 +0100
Local: Wed, Nov 19 2008 5:45 pm
Subject: Re: [erlang-questions] serializing functions

Matthias Lang <matth...@corelatus.se> writes:
> On Monday, November 17, damien morton wrote:
>> If I take the most basic of functions, e.g. fun()->0 end. and serialize it
>> using term_to_binary(), it seems that this function is serialized to 650
>> bytes.

> I'd guess you concluded that after trying it in the shell, not a
> module. IIRC, funs made in the shell are special, they carry around
> a complete (?) representation of the fun.

  i can confirm this.

 
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 »