From vmitsner Wed Oct 1 01:52:58 2008 From: vmitsner (Vladimir Mitsner) Date: Tue, 30 Sep 2008 18:52:58 -0500 Subject: [erlang-questions] ac_tab Message-ID: <32e4cadb0809301652u2601836aj1527059da04aff53@mail.gmail.com> I heard there is a way to configure a file such that at some point after startup of a node (with appropriate flags), the contents of that file are loaded into "ac_tab" - I have 2 questions : how do I specify the file in such a way that it is loaded into the ac_tab? And at what point would the contents of the file be loaded into ac_tab? Thank you. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20080930/3ba846a9/attachment-0001.html From dawsdesign Wed Oct 1 02:38:15 2008 From: dawsdesign (Matt Williamson) Date: Tue, 30 Sep 2008 20:38:15 -0400 Subject: [erlang-questions] Erlang SMTP module with support for attachments In-Reply-To: References: <1c3be50f0809300837h89038cfw7a2abbcec8888b9b@mail.gmail.com> Message-ID: I would also like to know. 2008/9/30 Juan Jose Comellas > Does anybody know if there's any open source Erlang module/library > available for sending emails with attachments? > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20080930/b007c0f4/attachment.html From dawsdesign Wed Oct 1 02:38:41 2008 From: dawsdesign (Matt Williamson) Date: Tue, 30 Sep 2008 20:38:41 -0400 Subject: [erlang-questions] Mnesia multi-table joins In-Reply-To: References: <6a3ae47e0809290545m3191f7b1ka872e4dd5da17cff@mail.gmail.com> <6a3ae47e0809290631h3871cfceie4bd5db04666d35c@mail.gmail.com> <6a3ae47e0809300936p5748e4a7k1934ea8c54c55c8b@mail.gmail.com> Message-ID: As you'll hear from many people, denormalize. Mnesia isn't really made to be a RDMS. On Tue, Sep 30, 2008 at 12:36 PM, Robert Raschke wrote: > On Tue, Sep 30, 2008 at 4:49 PM, wrote: > > Hi all, > > > > Changed subject of my last thread as it wasn't a performance issue! > > > > I have done some more digging and found that Mnesia appears to support > only joins across two tables. > > > > I have tried a cut down version of the below query using the two big > tables only and it is lightning quick. > > > > Does anyone know if there is a way to perform joins across more than two > tables? > > > > I fear I will have tripped on the last hurdle (I am currently prototyping > a proposed system) if I cant perform joins across more than two tables. > > > > Many Thanks, > > Dan > > > > -----Original Message----- > > From: RUBINO, Dana, GBM > > Sent: 30 September 2008 15:59 > > To: erlang-questions > > Subject: Extremely poor Mnesia performance > > > > > > Hey all, > > > > I am doing some benchmarking with Mnesia at the moment and am pretty > disappointed to say the least. > > > > I'm hoping I am doing something wrong. > > > > Running a 5 table join below: (two of the tables have ~50k rows the rest > a couple of hundred) > > > > execute(qlc:q([I#i.user_id || I <- mnesia:table(i), > > C <- mnesia:table(c), > > I#i.user_id =:= > C#c.user_id, > > I#i.group =:= "Group A", > > P <- mnesia:table(p), > > T <- mnesia:table(t), > > S <- mnesia:table(s), > > C#c.platform_id =:= > P#p.platform_id, > > C#c.trans_id =:= > T#t.trans_id, > > C#c.sales_id =:= > S#s.sales_id > > ])). > > > > On a normal RDBMS this query returns in < 1min. I am yet to get a result > from Mnesia and its been running for 10 mins. > > > > Is there anyway I can see what's going wrong with this query under the > hood? > > > > Thanks, > > Dan > > > > Do you really need one result set that makes use of values in all five > tables? Is it possible to have a i.user_id that does not have a > corresponding c.user_id, and can the c.platform_id, ... point to > non-existant p, ... entries? If not, that is, you have (conceptual) > foreign key constraints, then you can probably cut down the query to > just the i and c tables with conditions that the c.platform_id, ... > have values. > > Robby > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20080930/aa8452d8/attachment.html From vik Wed Oct 1 03:06:20 2008 From: vik (Vik Olliver) Date: Wed, 01 Oct 2008 14:06:20 +1300 Subject: [erlang-questions] Erlang SMTP module with support for attachments In-Reply-To: References: <1c3be50f0809300837h89038cfw7a2abbcec8888b9b@mail.gmail.com> Message-ID: <1222823180.15251.417.camel@localhost> On Tue, 2008-09-30 at 20:38 -0400, Matt Williamson wrote: > I would also like to know. > > 2008/9/30 Juan Jose Comellas > Does anybody know if there's any open source Erlang > module/library available for sending emails with attachments? You want erlmail. http://code.google.com/p/erlmail/ Vik :v) From colm.dougan Wed Oct 1 03:31:22 2008 From: colm.dougan (Colm Dougan) Date: Wed, 1 Oct 2008 02:31:22 +0100 Subject: [erlang-questions] Multiple ETS lookups Message-ID: <24d4f39c0809301831m6ca40d33id54979b468ad617@mail.gmail.com> Hi list, What do people think of the idea of adding a multiple ETS lookup function, analogous to the SQL 'IN' operator, where you can pass a list of keys and you get a list of matches? Something like : 1> T0 = ets:new(testtable, [set]). 15 2> ets:insert(T0, [{foo, 10}, {bar, 20}, {baz, 30}]). true 3> ets:multi_lookup(T0, [foo, bar, baz]). [{foo, 10},{bar,20},{baz,30}] 4> ets:multi_lookup(T0, [dog, foo, cat]). [{foo,10}] My motivation for this suggestion is mainly performance but I think it is also a common enough idiom that the interface would be generally useful. I realize that this problem has been solved in a more general way with match specs but unless I'm missing something using a match spec (even a compiled one) to do (say) 3 lookups is slower than doing 3 individual ets:lookup calls which defeats the point (in that case). Am I missing something here? I also find the match spec interface a bit unwieldy for such a simple operation (although I realize it is designed for flexibility). In my case the multiple ets lookup would help work around the performance dip I got in critical sections doing intensive lookups when I moved from non-SMP mode to SMP mode. I realize that relatively speaking the SMP locking is not that expensive unless there are lock conflicts but there is still a cost and when doing intensive lookups you definitely notice it. Being able to "unroll" my lookups to do (say) 4 or 8 at once and only incur the locking overheads a quarter of the time would be a big win. Yeah I know people will then potentially be able to do nasty things like try to do too many lookups at once, but then again they could just not do that. Anyway, just throwing the idea out there to be shot at. Thanks, Colm From lloy0076 Wed Oct 1 04:58:38 2008 From: lloy0076 (David Lloyd) Date: Wed, 01 Oct 2008 12:28:38 +0930 Subject: [erlang-questions] Simple OTP Question... Message-ID: <48E2E75E.4020000@adam.com.au> Hi There, My source is: -module(ping). -behaviour(gen_server). -export([init/1, terminate/2, code_change/3]). -export([handle_call/3, handle_cast/2, handle_info/2]). init(Args) -> {ok, "Started"}. handle_call(Request, From, State) -> true, {reply, "Pong", State}. handle_cast(Request, State) -> {stop, "Not implemented", State}. handle_info(Info, State) -> {stop, "Not implemented", State}. terminate(Reason, State) -> true. code_change(OldVsn, State, Extra) -> State. bash-3.00$ erl Erlang (BEAM) emulator version 5.5.5 [source] [async-threads:0] [kernel-poll:false] Eshell V5.5.5 (abort with ^G) 1> c(ping). ./ping.erl:7: Warning: variable 'Args' is unused ./ping.erl:10: Warning: variable 'From' is unused ./ping.erl:10: Warning: variable 'Request' is unused ./ping.erl:14: Warning: variable 'Request' is unused ./ping.erl:17: Warning: variable 'Info' is unused ./ping.erl:20: Warning: variable 'Reason' is unused ./ping.erl:20: Warning: variable 'State' is unused ./ping.erl:23: Warning: variable 'Extra' is unused ./ping.erl:23: Warning: variable 'OldVsn' is unused {ok,ping} 2> gen_server:start({ok, pserv}, ping, {args}, []). =ERROR REPORT==== 1-Oct-2008::12:23:47 === Error in process <0.30.0> with exit value: {function_clause,[{gen,where,[{ok,pserv}]},{gen,start,6},{erl_eval,do_apply,5},{shell,exprs,6},{shell,eval_loop,3}]} ** exited: {undef,[{shell_default,handle_call,[1,2,3]}, {erl_eval,do_apply,5}, {shell,exprs,6}, {shell,eval_loop,3}]} ** However, if I remove the "true, " in the source, the gen_server starts. I can't figure out what's causing this behaviour and I'm looking at the STDLIB documents and Programming Erlan. DSL From erlang-questions_efine Wed Oct 1 05:27:40 2008 From: erlang-questions_efine (Edwin Fine) Date: Tue, 30 Sep 2008 23:27:40 -0400 Subject: [erlang-questions] Simple OTP Question... In-Reply-To: <48E2E75E.4020000@adam.com.au> References: <48E2E75E.4020000@adam.com.au> Message-ID: <6c2563b20809302027l62afbe2et98c5194ad5992c7c@mail.gmail.com> You're calling gen_server:start() with the wrong arguments. This may help: 25> c(ping). ./ping.erl:7: Warning: variable 'Args' is unused ./ping.erl:10: Warning: variable 'From' is unused ./ping.erl:10: Warning: variable 'Request' is unused ./ping.erl:14: Warning: variable 'Request' is unused ./ping.erl:17: Warning: variable 'Info' is unused ./ping.erl:20: Warning: variable 'Reason' is unused ./ping.erl:20: Warning: variable 'State' is unused ./ping.erl:23: Warning: variable 'Extra' is unused ./ping.erl:23: Warning: variable 'OldVsn' is unused {ok,ping} 26> {ok, Pid} = gen_server:start({local, myserver}, ping, [], []). {ok,<0.97.0>} 27> gen_server:call(myserver, some_request). "Pong" 28> gen_server:call(myserver, {arbitrarily_complex,[some_request]}). "Pong" 29> exit(Pid,normal). true 30> erlang:is_process_alive(Pid). true 31> exit(Pid,shutdown). true 32> erlang:is_process_alive(Pid). false 33> f(Pid). ok 34> {ok, Pid} = gen_server:start(ping, [], []). {ok,<0.106.0>} 35> gen_server:call(Pid, some_request). "Pong" 36> exit(Pid,shutdown). true On Tue, Sep 30, 2008 at 10:58 PM, David Lloyd wrote: > > Hi There, > > My source is: > > -module(ping). > -behaviour(gen_server). > > -export([init/1, terminate/2, code_change/3]). > -export([handle_call/3, handle_cast/2, handle_info/2]). > > init(Args) -> > {ok, "Started"}. > > handle_call(Request, From, State) -> > true, > {reply, "Pong", State}. > > handle_cast(Request, State) -> > {stop, "Not implemented", State}. > > handle_info(Info, State) -> > {stop, "Not implemented", State}. > > terminate(Reason, State) -> > true. > > code_change(OldVsn, State, Extra) -> > State. > > > bash-3.00$ erl > Erlang (BEAM) emulator version 5.5.5 [source] [async-threads:0] > [kernel-poll:false] > > Eshell V5.5.5 (abort with ^G) > 1> c(ping). > ./ping.erl:7: Warning: variable 'Args' is unused > ./ping.erl:10: Warning: variable 'From' is unused > ./ping.erl:10: Warning: variable 'Request' is unused > ./ping.erl:14: Warning: variable 'Request' is unused > ./ping.erl:17: Warning: variable 'Info' is unused > ./ping.erl:20: Warning: variable 'Reason' is unused > ./ping.erl:20: Warning: variable 'State' is unused > ./ping.erl:23: Warning: variable 'Extra' is unused > ./ping.erl:23: Warning: variable 'OldVsn' is unused > {ok,ping} > 2> gen_server:start({ok, pserv}, ping, {args}, []). > > =ERROR REPORT==== 1-Oct-2008::12:23:47 === > Error in process <0.30.0> with exit value: > > {function_clause,[{gen,where,[{ok,pserv}]},{gen,start,6},{erl_eval,do_apply,5},{shell,exprs,6},{shell,eval_loop,3}]} > > ** exited: {undef,[{shell_default,handle_call,[1,2,3]}, > {erl_eval,do_apply,5}, > {shell,exprs,6}, > {shell,eval_loop,3}]} ** > > However, if I remove the "true, " in the source, the gen_server starts. > > I can't figure out what's causing this behaviour and I'm looking at the > STDLIB documents and Programming Erlan. > > DSL > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20080930/f542e362/attachment-0001.html From zerthurd Wed Oct 1 05:27:55 2008 From: zerthurd (Maxim Treskin) Date: Wed, 1 Oct 2008 10:27:55 +0700 Subject: [erlang-questions] Simple OTP Question... In-Reply-To: <48E2E75E.4020000@adam.com.au> References: <48E2E75E.4020000@adam.com.au> Message-ID: Just read `erl -man gen_server`. ====== start(ServerName, Module, Args, Options) -> Result ServerName = {local, Name} | {global, GlobalName} ====== ServerName is NOT {ok, Name} > However, if I remove the "true, " in the source, the gen_server starts. Which of? -- Maxim Treskin From ok Wed Oct 1 05:50:06 2008 From: ok (Richard O'Keefe) Date: Wed, 1 Oct 2008 16:50:06 +1300 Subject: [erlang-questions] The Erlang Rationale In-Reply-To: <3dbc6d1c0809300630q35221794jf0922f370de6dd04@mail.gmail.com> References: <3dbc6d1c0809291502m3ad2147djfdc652a8e5c7a157@mail.gmail.com> <48E1F395.5040501@gmail.com> <3dbc6d1c0809300519kd46dbadsdfb670f71865b5@mail.gmail.com> <48E21D43.1040509@gmail.com> <4ac8254d0809300609m7c72c6b2je9774a70c629acf8@mail.gmail.com> <3dbc6d1c0809300630q35221794jf0922f370de6dd04@mail.gmail.com> Message-ID: On 1 Oct 2008, at 2:30 am, Robert Virding wrote: > OK, OK, OK, enough already! :-) I will fix the next version in PDF. > And I thought this was a bunch of computer savvy people who would > just laugh at Word format. I take software piracy seriously, so I do not laugh when I see people giving financial support to a large company convicted of software piracy, especially when there are free alternatives (AbiWord, OpenOffice) and when an open format (HTML) would have done just as good a job. > "i.e. large switches" should be "i.e., large switches". "handle large number" should be "handle a large number" Immutable data structures: (1) they eliminate the classic OO problem "what happens when you are iterating over a collection and the collection changes" because it can't; (2) just today in Haskell-Caf? someone was complaining about a data structure in C# (hence in F#) not being thread-safe for no apparent reason, immutable data structures means you can't make a thread-unsafe data structure. "all messages sent were complete, no partial messages" -- if you are using two or more node, what exactly stops a message sent from one node to another arriving only in part? Communications networks are unreliable, after all. "The level of security in the message protocol" -- I think you need to explain why asynchrony avoids problems with this, it's certainly not obvious to me. "Typing" "I still think is was" s/is/it/ "distribution were nodes were" s/were nodes/where nodes/ "Generic requests to an i/o server" 1,$s:i/o:I/O:g "while the with" s/the // I never did get my head around the I/O protocol, not least because it didn't seem to be written down anywhere. I am very happy indeed to see this discussion of I/O requests. Being a Bear of Very Little Brain, I *still* don't get how to do the continuation stuff. It might be worth while splitting this out as a separate document and putting in enough idiot-level examples so that I finally get it. [Beg beg.] "Process Groups" The first straightforward explanation of the idea I've ever seen. Are there any plans to extend this feature or its use? 'It would be good to have some example programs' -- you took the words out of my keyboard. "SHAPE \* MERGEFORMAT" I take to be an artefact of the way the PDF was produced. "the '=' operator" What you do not mention, and what would strengthen your position, is that in those languages that have 'let', the '=' sign is usually an essential part of the syntax. ML let val = in end Haskell let = in where = ['let' and 'where' were in ISWIM, if I recall correctly.] So there is nothing in the least unusual in the functional world about = . "take apart you cake" s/you/your/ The thing that *is* rather unusual is allowing '=' inside function calls and having the bindings percolate out. The introduction of 'fun' and list comprehensions has also done bad things to the simple 'the scope of a variable is the entire clause it occurs in' rule. "Macros" Named constants should have been = at top level. I've tried rewriting some modules that way to see what it looks like and it's beautiful. I grant the utility of -include, but that's not macros. If I want M4 I know where to find it. I have CScout to help me cope with C code that's full of macros, but unless I can talk Diomidis Spinellis into it (and he has other maddened grizzly bears to stun) there isn't and won't be an EScout. Macros make maintenance *harder*. "en Erlang point of view" s/en/an/ "Variable scoping and 'let'" This is the perfect opportunity to mention LFE and point out that people who want to try an alternative approach to scoping have something they can play with. I note that 'begin' ... 'end' were originally introduced in the form "begin within end". "Group leader Group leader Process group Process group "user" User driver Job 1 Job 2 " I take these lines at the end to be another artefact of the Weird->PDF conversion process. From devdoer2 Wed Oct 1 06:00:28 2008 From: devdoer2 (devdoer bird) Date: Wed, 1 Oct 2008 12:00:28 +0800 Subject: [erlang-questions] what does open_port({fd,0,1},...) do? Message-ID: HI: I found erlang's windows version use user.erl module to process terminal IO and user.erl calls function: open_port({fd,0,1},PortSettings) to open a port. I can't find which driver source file in erlang package corresponding to the {fd,0,1} port. I also modify the erlang's linux version to use user.erl instead user_drv.erl to process terminal IO,for I found user.erl can display CJK words correctly. It works except the control input such as cursor move input like "<-" ,"->" will be showed like this "^[[D" . So I want to find the {fd,0,1} port process code to research more. Can some guy give some clues? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081001/1b9f6cf2/attachment.html From zerthurd Wed Oct 1 07:11:19 2008 From: zerthurd (Maxim Treskin) Date: Wed, 1 Oct 2008 12:11:19 +0700 Subject: [erlang-questions] what does open_port({fd,0,1},...) do? In-Reply-To: References: Message-ID: erl -man erlang ===== open_port(PortName, PortSettings) -> port() PortName = {spawn, Command} | {fd, In, Out} Command = string() In = Out = int() ... {fd, In, Out}: Allows an Erlang process to access any currently opened file descriptors used by Erlang. The file descriptor In can be used for standard input, and the file descriptor Out for standard output. It is only used for various servers in the Erlang operating system (shell and user). Hence, its use is very limited. ===== -- Maxim Treskin -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081001/a918a739/attachment.html From ulf Wed Oct 1 08:26:49 2008 From: ulf (Ulf Wiger) Date: Wed, 1 Oct 2008 08:26:49 +0200 Subject: [erlang-questions] Multiple ETS lookups In-Reply-To: <24d4f39c0809301831m6ca40d33id54979b468ad617@mail.gmail.com> References: <24d4f39c0809301831m6ca40d33id54979b468ad617@mail.gmail.com> Message-ID: <8209f740809302326l4415b476vd82ed27cbed7b7ea@mail.gmail.com> I posted a slightly more general suggestion a while back: http://www.erlang.org/pipermail/erlang-questions/2007-May/026440.html http://www.erlang.org/pipermail/erlang-questions/2007-June/026998.html http://www.erlang.org/pipermail/erlang-questions/2007-June/027004.html The main reason for doing this, I think, would be atomicity, without having to go either through a serializing process or mnesia. Conceptually, using a process is a lot cleaner. The problem (apart from forcing you to write more code) is that you double the amount of copying needed... BR, Ulf W 2008/10/1 Colm Dougan : > Hi list, > > What do people think of the idea of adding a multiple ETS lookup > function, analogous to the SQL 'IN' operator, where you can pass a > list of keys and you get a list of matches? > > Something like : > > 1> T0 = ets:new(testtable, [set]). > 15 > 2> ets:insert(T0, [{foo, 10}, {bar, 20}, {baz, 30}]). > true > 3> ets:multi_lookup(T0, [foo, bar, baz]). > [{foo, 10},{bar,20},{baz,30}] > 4> ets:multi_lookup(T0, [dog, foo, cat]). > [{foo,10}] > > My motivation for this suggestion is mainly performance but I think it > is also a common enough idiom that the interface would be generally > useful. > > I realize that this problem has been solved in a more general way with > match specs but unless I'm missing something using a match spec (even > a compiled one) to do (say) 3 lookups is slower than doing 3 > individual ets:lookup calls which defeats the point (in that case). > Am I missing something here? I also find the match spec interface a > bit unwieldy for such a simple operation (although I realize it is > designed for flexibility). > > In my case the multiple ets lookup would help work around the > performance dip I got in critical sections doing intensive lookups > when I moved from non-SMP mode to SMP mode. I realize that relatively > speaking the SMP locking is not that expensive unless there are lock > conflicts but there is still a cost and when doing intensive lookups > you definitely notice it. Being able to "unroll" my lookups to do > (say) 4 or 8 at once and only incur the locking overheads a quarter of > the time would be a big win. > > Yeah I know people will then potentially be able to do nasty things > like try to do too many lookups at once, but then again they could > just not do that. > > Anyway, just throwing the idea out there to be shot at. > > Thanks, > Colm > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From pguyot Wed Oct 1 08:43:47 2008 From: pguyot (Paul Guyot) Date: Wed, 1 Oct 2008 08:43:47 +0200 Subject: [erlang-questions] Questions on C/Java nodes Message-ID: Hello, The tutorial for the C nodes (I'm pretty sure I've seen some similar code for Java nodes) goes like this: listen(..., 5) erl_publish(...) fd = erl_accept(...) while (true) { erl_receive_msg(fd, ...) } From what I understand, the C node can only have one peer (the first one that connects). Yet, still in the tutorial sample code [1], listen (2) is called with a backlog of 5. Is there any reason why the tutorial code isn't a regular fork(2) or select(2)-based server code, except for simplicity (and that this probably wouldn't be portable on Windows)? On Unix, can select(2) be used on the file descriptor returned by erl_accept? Still on the C nodes, I am confused by the creation parameter of erl_connect_init. The man page erl_connect(3) says: > creation helps identify a particular instance of a C node. In > particular, it can help prevent us from receiving messages sent > to an earlier process with the same registered name. > > A C node acting as a server will be assigned a creation number > when it calls erl_publish(). and then the sample code below gives 0. In which case should we provide something different from 0? Paul [1] http://erlang.org/doc/tutorial/cnode.html From mats.cronqvist Wed Oct 1 09:37:04 2008 From: mats.cronqvist (Mats Cronqvist) Date: Wed, 01 Oct 2008 09:37:04 +0200 Subject: [erlang-questions] The Erlang Rationale In-Reply-To: References: <3dbc6d1c0809291502m3ad2147djfdc652a8e5c7a157@mail.gmail.com> <48E1F395.5040501@gmail.com> <3dbc6d1c0809300519kd46dbadsdfb670f71865b5@mail.gmail.com> <48E21D43.1040509@gmail.com> <4ac8254d0809300609m7c72c6b2je9774a70c629acf8@mail.gmail.com> <3dbc6d1c0809300630q35221794jf0922f370de6dd04@mail.gmail.com> Message-ID: <48E328A0.6070109@gmail.com> Richard O'Keefe wrote: > On 1 Oct 2008, at 2:30 am, Robert Virding wrote: > > >> OK, OK, OK, enough already! :-) I will fix the next version in PDF. >> And I thought this was a bunch of computer savvy people who would >> just laugh at Word format. >> > > I take software piracy seriously, > so I do not laugh when I see people giving financial > support to a large company convicted of software piracy, > especially when there are free alternatives (AbiWord, > OpenOffice) and when an open format (HTML) would have > done just as good a job. +1 > "Macros" > > [...] Macros make maintenance *harder*. > +10 mats From joelr1 Wed Oct 1 12:04:16 2008 From: joelr1 (Joel Reymont) Date: Wed, 1 Oct 2008 11:04:16 +0100 Subject: [erlang-questions] best way to implement a "barrier" Message-ID: <23043890-185B-4AF4-BC42-5F2BDB9EF974@gmail.com> I need to make sure that a bunch of processes start doing work all at the same time. I'm looking at 10-50k processes. What is the best way to implement this? To be more precise, I need to make sure my poker games hang around until told to start. What happens otherwise is that I try to start, say, 10k games and by the time games 7-10k start, the first few thousand may have already finished. This complicates counting the number of games running concurrently. Thanks, Joel -- wagerlabs.com From richardc Wed Oct 1 12:38:52 2008 From: richardc (Richard Carlsson) Date: Wed, 01 Oct 2008 12:38:52 +0200 Subject: [erlang-questions] best way to implement a "barrier" In-Reply-To: <23043890-185B-4AF4-BC42-5F2BDB9EF974@gmail.com> References: <23043890-185B-4AF4-BC42-5F2BDB9EF974@gmail.com> Message-ID: <48E3533C.8040606@it.uu.se> Joel Reymont wrote: > I need to make sure that a bunch of processes start doing work all at > the same time. I'm looking at 10-50k processes. What is the best way > to implement this? > > To be more precise, I need to make sure my poker games hang around > until told to start. What happens otherwise is that I try to start, > say, 10k games and by the time games 7-10k start, the first few > thousand may have already finished. This complicates counting the > number of games running concurrently. How exact do you need the synchronization to be? The simplest barrier is a receive that waits for a start message. But if that is not exact enough (some have finished before others have even woken up), you might try a clock synchronization (unless that will overload the Erlang timer wheel): tell each process to go into a state waiting for a specific time (expressed as a datetime). Each process will then individually calculate how many milliseconds that is from now, and go into a simple 'receive after N -> ok end' wait. Possibly, this will wake them all up more simultaneously than the message-based method. The set time must be sufficiently far ahead that all processes have had time to react and enter the wait state. /Richard From joelr1 Wed Oct 1 13:45:28 2008 From: joelr1 (Joel Reymont) Date: Wed, 1 Oct 2008 12:45:28 +0100 Subject: [erlang-questions] best way to implement a "barrier" In-Reply-To: <48E3533C.8040606@it.uu.se> References: <23043890-185B-4AF4-BC42-5F2BDB9EF974@gmail.com> <48E3533C.8040606@it.uu.se> Message-ID: On Oct 1, 2008, at 11:38 AM, Richard Carlsson wrote: > How exact do you need the synchronization to be? The simplest barrier > is a receive that waits for a start message That's what I was thinking. The question then is how to ensure that all processes get the start message more or less at the same time. I guess this is the question of how long it takes to send 10k-50k start messages. > But if that is not exact > enough (some have finished before others have even woken up), you > might > try a clock synchronization Great suggestion! Thanks, Joel -- wagerlabs.com From nem Wed Oct 1 14:07:00 2008 From: nem (Geoff Cant) Date: Wed, 01 Oct 2008 14:07:00 +0200 Subject: [erlang-questions] Erlang SMTP module with support for attachments In-Reply-To: <1222823180.15251.417.camel@localhost> (Vik Olliver's message of "Wed, 01 Oct 2008 14:06:20 +1300") References: <1c3be50f0809300837h89038cfw7a2abbcec8888b9b@mail.gmail.com> <1222823180.15251.417.camel@localhost> Message-ID: Vik Olliver writes: > On Tue, 2008-09-30 at 20:38 -0400, Matt Williamson wrote: >> I would also like to know. >> >> 2008/9/30 Juan Jose Comellas >> Does anybody know if there's any open source Erlang >> module/library available for sending emails with attachments? > > You want erlmail. > > http://code.google.com/p/erlmail/ > > Vik :v) You may also be interested in my mime module (http://github.com/archaelus/erlmail/tree/mime/src/mail_mime.erl) which provides mime encoding and some functions to make that easier to use. I should really make a cut down distribution of smtpc+mail_mime at some point for the people who just want to be able to generate mail and attachments and fire it off to a smarthost. Cheers, --Geoff From richardc Wed Oct 1 14:58:39 2008 From: richardc (Richard Carlsson) Date: Wed, 01 Oct 2008 14:58:39 +0200 Subject: [erlang-questions] best way to implement a "barrier" In-Reply-To: References: <23043890-185B-4AF4-BC42-5F2BDB9EF974@gmail.com> <48E3533C.8040606@it.uu.se> Message-ID: <48E373FF.40807@it.uu.se> Joel Reymont wrote: > > On Oct 1, 2008, at 11:38 AM, Richard Carlsson wrote: > >> How exact do you need the synchronization to be? The simplest barrier >> is a receive that waits for a start message > > That's what I was thinking. The question then is how to ensure that all > processes get the start message more or less at the same time. I guess > this is the question of how long it takes to send 10k-50k start messages. A quick experiment from the command line: 200 ms for 50000 messages (not including the time to traverse the list), on the local machine. Fast enough? For a bunch of connected nodes, I'd avoid sending 50000 separate messages - if possible, send 1 message to each node, telling it to broadcast to only its local processes. /Richard From psa Wed Oct 1 15:19:52 2008 From: psa (=?ISO-8859-1?Q?Paulo_S=E9rgio_Almeida?=) Date: Wed, 01 Oct 2008 14:19:52 +0100 Subject: [erlang-questions] best way to implement a "barrier" In-Reply-To: References: <23043890-185B-4AF4-BC42-5F2BDB9EF974@gmail.com><48E3533C.804060 6@it.uu.se> Message-ID: <48E378F8.10600@di.uminho.pt> Joel Reymont wrote: > On Oct 1, 2008, at 11:38 AM, Richard Carlsson wrote: > >> How exact do you need the synchronization to be? The simplest barrier >> is a receive that waits for a start message > > That's what I was thinking. The question then is how to ensure that > all processes get the start message more or less at the same time. I > guess this is the question of how long it takes to send 10k-50k start > messages. Here is a version using links and trap_exit, intending to "send" the messages atomically, before being preempted. Does anyone know if the propagation of EXITs upon termination is atomic (at least within the same node) or it can be preempted and resumed later? Regards, Paulo -- -module(barrier). -export([init/0, wait/1, go/1]). init() -> spawn(fun() -> receive go -> ok end end). wait(Barrier) -> TE = process_flag(trap_exit, true), link(Barrier), receive {'EXIT', Barrier, normal} -> ok end, process_flag(trap_exit, TE). go(Barrier) -> Barrier ! go. From erlang-questions_efine Wed Oct 1 15:49:06 2008 From: erlang-questions_efine (Edwin Fine) Date: Wed, 1 Oct 2008 09:49:06 -0400 Subject: [erlang-questions] The Erlang Rationale In-Reply-To: References: <3dbc6d1c0809291502m3ad2147djfdc652a8e5c7a157@mail.gmail.com> <48E1F395.5040501@gmail.com> <3dbc6d1c0809300519kd46dbadsdfb670f71865b5@mail.gmail.com> <48E21D43.1040509@gmail.com> <4ac8254d0809300609m7c72c6b2je9774a70c629acf8@mail.gmail.com> <3dbc6d1c0809300630q35221794jf0922f370de6dd04@mail.gmail.com> Message-ID: <6c2563b20810010649xdb362dcyefc9e361608b33f7@mail.gmail.com> This is a dissenting vote regarding macros. Macros *can* make maintenance harder, just like gotos *can* create spaghetti code. Neither of them are intrinsically bad, merely easy to misuse. Used with care and discipline, they both arguably have a place in good programming practice. Now I may get shot down in flames for saying this, but tail recursion in Erlang is effectively a restricted form of goto, and it's used a lot (not by choice over some other construct, though - the language design forces the usage). There are some things that macros can do that I have not found as easy (or possible) to do some other way, for example: -define(LOG_DBG(Msg, ArgList), iutil_log:log_debug(?MODULE, ?LINE, Msg, ArgList)). Example usage: ?LOG_DBG("Received ~p from ~p~n", [Msg, Socket]). The alternative is ugly. iutil_log:log_debug(?MODULE, ?LINE, "Received ~p from ~p~n", [Msg, Socket]). If I find that debug logging is causing too much overhead, I can decide to conditionally compile it: -ifdef(DEBUG). -define(LOG_DBG(Msg, ArgList), iutil_log:log_debug(?MODULE, ?LINE, Msg, ArgList)). -else. -define(LOG_DBG(Msg, ArgList), ok). -endif. A minor inconvenience of the above is that if it uses variables that are not otherwise used, you can get compile warnings when debug logging is disabled. This is easily fixed by using the underscore: _Unused. If I don't like having to recompile the code to enable and disable debug logging, but want to turn it on and off at run-time (and still have negligible overhead when debug logging is disabled), I can do this (and the source code using this does not change in any way, but of course must undergo a once-off recompilation): -define( LOG_DBG(Msg, ArgList), case iutil_log:ok_to_log(debug) of true -> iutil_log:log_debug(?MODULE, ?LINE, Msg, ArgList); false -> ok end ). Checking if the Msg and ArgList should be evaluated before calling saves, at the cost of an efficient function call, potentially enormous amounts of unnecessary list creation and destruction (and garbage collection), not to mention any evaluation of the list elements that might be needed. In this case I would argue that the macro makes the code *more* maintainable and easier to read, while keeping it efficient. Agreed, if the macro changes (and this class of macro seldom changes) I will need to recompile the dependent code, and this is definitely not good, but as Lord Farquhar said, "[Many of you may be killed, but] it is a sacrifice I am willing to make." ;-) On Tue, Sep 30, 2008 at 11:50 PM, Richard O'Keefe wrote: > > On 1 Oct 2008, at 2:30 am, Robert Virding wrote: > > > OK, OK, OK, enough already! :-) I will fix the next version in PDF. > > And I thought this was a bunch of computer savvy people who would > > just laugh at Word format. > > I take software piracy seriously, > so I do not laugh when I see people giving financial > support to a large company convicted of software piracy, > especially when there are free alternatives (AbiWord, > OpenOffice) and when an open format (HTML) would have > done just as good a job. > > > "i.e. large switches" should be "i.e., large switches". > "handle large number" should be "handle a large number" > > Immutable data structures: (1) they eliminate the classic > OO problem "what happens when you are iterating over a > collection and the collection changes" because it can't; > (2) just today in Haskell-Caf? someone was complaining about > a data structure in C# (hence in F#) not being thread-safe > for no apparent reason, immutable data structures means you > can't make a thread-unsafe data structure. > > "all messages sent were complete, no partial messages" > -- if you are using two or more node, what exactly stops > a message sent from one node to another arriving only in > part? Communications networks are unreliable, after all. > > "The level of security in the message protocol" -- I think > you need to explain why asynchrony avoids problems with > this, it's certainly not obvious to me. > > "Typing" > "I still think is was" s/is/it/ > "distribution were nodes were" s/were nodes/where nodes/ > > "Generic requests to an i/o server" > 1,$s:i/o:I/O:g > "while the with" s/the // > > I never did get my head around the I/O protocol, not least > because it didn't seem to be written down anywhere. I am > very happy indeed to see this discussion of I/O requests. > Being a Bear of Very Little Brain, I *still* don't get how > to do the continuation stuff. > > It might be worth while splitting this out as a separate > document and putting in enough idiot-level examples so that > I finally get it. [Beg beg.] > > "Process Groups" > The first straightforward explanation of the idea I've ever > seen. Are there any plans to extend this feature or its use? > 'It would be good to have some example programs' -- you took > the words out of my keyboard. > > "SHAPE \* MERGEFORMAT" I take to be an artefact of the way > the PDF was produced. > > "the '=' operator" > > What you do not mention, and what would strengthen your position, > is that in those languages that have 'let', the '=' sign is usually > an essential part of the syntax. > ML let val = in end > Haskell let = in > where = > ['let' and 'where' were in ISWIM, if I recall correctly.] > So there is nothing in the least unusual in the functional world > about = . > > "take apart you cake" s/you/your/ > > The thing that *is* rather unusual is allowing '=' inside > function calls and having the bindings percolate out. The > introduction of 'fun' and list comprehensions has also done > bad things to the simple 'the scope of a variable is the > entire clause it occurs in' rule. > > "Macros" > > Named constants should have been = > at top level. I've tried rewriting some modules that way to see > what it looks like and it's beautiful. I grant the utility of > -include, but that's not macros. If I want M4 I know where to > find it. I have CScout to help me cope with C code that's full > of macros, but unless I can talk Diomidis Spinellis into it (and > he has other maddened grizzly bears to stun) there isn't and won't > be an EScout. Macros make maintenance *harder*. > > "en Erlang point of view" s/en/an/ > > "Variable scoping and 'let'" > > This is the perfect opportunity to mention LFE and point out > that people who want to try an alternative approach to scoping > have something they can play with. > > I note that 'begin' ... 'end' were originally introduced in the > form "begin within end". > > "Group leader > Group leader > > Process group > Process group > "user" > User driver > Job 1 > Job 2 > " > I take these lines at the end to be another artefact of the > Weird->PDF conversion process. > > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081001/c28b4c5e/attachment-0001.html From devdoer2 Wed Oct 1 17:15:46 2008 From: devdoer2 (devdoer bird) Date: Wed, 1 Oct 2008 23:15:46 +0800 Subject: [erlang-questions] what does open_port({fd,0,1},...) do? In-Reply-To: References: Message-ID: Thanks .I read the manual before this mail.But the manul is not very clear. Can you give more details please? Such as why this special {fd,In,Out} port is needed? 2008/10/1 Maxim Treskin > erl -man erlang > > ===== > open_port(PortName, PortSettings) -> port() > PortName = {spawn, Command} | {fd, In, Out} > Command = string() > In = Out = int() > ... > {fd, In, Out}: > Allows an Erlang process to access any currently > opened file descriptors used by Erlang. The file descriptor In can be > used for standard input, and the file descriptor Out > for standard output. It is only used for various servers in the > Erlang operating system (shell and user). Hence, its > use is very limited. > ===== > > -- > Maxim Treskin > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081001/3b168924/attachment.html From zerthurd Wed Oct 1 17:50:54 2008 From: zerthurd (Maxim Treskin) Date: Wed, 1 Oct 2008 22:50:54 +0700 Subject: [erlang-questions] what does open_port({fd,0,1},...) do? In-Reply-To: References: Message-ID: This option provides access to file descriptors opened by Erlang, i.e. stdin and stdout. So, you can directly write to and read from this descriptors from erlang process. Normally, you must not use this feature. On 01/10/2008, devdoer bird wrote: > Thanks .I read the manual before this mail.But the manul is not very clear. > Can you give more details please? Such as why this special {fd,In,Out} port > is needed? -- Maxim Treskin From joelr1 Wed Oct 1 17:57:50 2008 From: joelr1 (Joel Reymont) Date: Wed, 1 Oct 2008 16:57:50 +0100 Subject: [erlang-questions] Erlang doesn't suck Message-ID: Not once the pain goes away and only the results stick around. I spent a grueling 1+ week refactoring OpenPoker and wishing for static typing. I started at number of git branches, only to be thrown away a day or two later. Many were the times when I wished to tear my hair out and throw Erlang far and away from my terrace and towards the Atlantic ocean. I do have an extensive test harness and so the best approach proved to be committing reasonably small changes once all tests pass. The end result is that OpenPoker scales MUCH better now, even on a single VM! My workstation is a Mac Pro, 2x2.8Ghz QuadXeon with 14Gb of RAM. A while ago I deliberated between Amazon EC2 and Joyent and decided to host with the latter. For the purposes of testing, Joyent provided me with an 8 Core x86 Solaris Nevada system w/ a 2 GiB memory cap where I can burst to 95% CPU Utilization. A friendly member of this forum gave me access to a Solaris/Niagara system but I haven't had a change to test on it yet so I'll only compare my Mac and Joyent. Here are the test results, statistics collected every 30 seconds. My Mac ------ With SMP... 3000 games started, 15115 players ... 3000 games finished Elapsed: 181.960007s, Average run time: 0.06065333566666666 seconds 5000 games started, 25404 players ... 5000 games finished Elapsed: 329.646545s, Average run time: 0.065929309 seconds 7450 games started, 37890 players ... 7450 games finished Elapsed: 554.956259s, Average run time: 0.07407317925787507 seconds Without SMP (disabled)... (1)3> mb:test(localhost, 3000, 3000). Simulating gameplay with 3000 games... Waiting for games to end... 50 games started, 262 players =INFO REPORT==== 1-Oct-2008::16:00:01 === requests: 26065 bytes: 466134 requests_per_second: 868 bytes_per_second: 15536 1750 games started, 8786 players =INFO REPORT==== 1-Oct-2008::16:00:31 === requests: 26695 bytes: 303955 requests_per_second: 889 bytes_per_second: 10128 1800 games started, 9030 players =INFO REPORT==== 1-Oct-2008::16:01:01 === requests: 38856 bytes: 484091 requests_per_second: 1295 bytes_per_second: 16136 3000 games started, 15115 players 50 games finished =INFO REPORT==== 1-Oct-2008::16:01:31 === requests: 22199 bytes: 249774 requests_per_second: 739 bytes_per_second: 8323 2400 games finished 3000 games finished =INFO REPORT==== 1-Oct-2008::16:02:01 === requests: 14249 bytes: 122289 requests_per_second: 474 bytes_per_second: 4076 Elapsed: 121.541805s, Average run time: 0.040513935 seconds I figured I'll leave SMP disabled since I will likely be running a few VMs anyway. I'm assuming that 8 non-SMP VMs on an 8-core machines are much better than 8 VMs with 8-core SMP. Joyent Labs ----------- (1)3> mb:test(localhost, 3000, 3000). Simulating gameplay with 3000 games... Waiting for games to end... =INFO REPORT==== 1-Oct-2008::14:54:37 === requests: 38588 bytes: 710144 requests_per_second: 1286 bytes_per_second: 23670 2900 games started, 14614 players =INFO REPORT==== 1-Oct-2008::14:55:07 === requests: 40604 bytes: 482419 requests_per_second: 1351 bytes_per_second: 16055 900 games finished 3000 games finished =INFO REPORT==== 1-Oct-2008::14:55:37 === requests: 48872 bytes: 433680 requests_per_second: 1628 bytes_per_second: 14453 Elapsed: 68.21404s, Average run time: 0.02273801333333333 seconds As you can see, the test finished twice as fast at Joyent and the number of request per second stayed high. How did I achieve my scalability increases? I switched to a closure based binary serialization approach [1] based on Andrew Kennedy's Pickler Combinators. I think performance can be better but I'm quite content with describing packets like this: Pickler = record(foo, { byte(), record(bar, { int(), record(baz, { sshort(), list(byte(), byte()) }) }) }), [1] http://www.wagerlabs.com/erlang/pickle.erl I also removed an Erlang-style deadlock from my code. I have players and games. Erlang/OTP gen_server has both cast (fire and forget) and call (wait for reply) mechanisms. My games go in pairs of a gen_fsm driving the poker game logic and a gen_server doing the house keeping. My players called games, games called players and everything may have been fine if I didn't use game timers. With a high server load I would get into a situation where a player was expecting a game reply, a timer fired and the game called the player. A deadlock would ensue and one of the calls would time out. I found out the reason by grabbing the process info of both the player and the game upon a timeout and realizing that there was perhaps a single message in each queue but both processes were waiting on each another. I also poked around in Erlang crash dumps but this didn't prove as useful. Then I made sure that outgoing packets had the numeric game and player ids stuffed in them at the source. My previous approach had game and player process ids in the packet and had the serialization bits call each process to get its id. This really limited scalability and slowed things down. More importantly, this was another source of deadlocks since a game would invoke a serialization function that called back into the very same game. Last but not least, my benchmarking approach is a bit flawed since I can only start 7.5k games on my Mac and 8.6K games at Joyent. This is because my benchmark tool winds down once the number of finished games equals the number of games started, disregarding the total number of games I want to start in the first place. I don't see 15K players online at the same time for the same reason. My next step is to make sure all games run when the start pistol fires and to distribute testing among several VMs. Thanks, Joel -- wagerlabs.com From kostis Wed Oct 1 18:17:42 2008 From: kostis (Kostis Sagonas) Date: Wed, 01 Oct 2008 19:17:42 +0300 Subject: [erlang-questions] Question about gen_event Message-ID: <48E3A2A6.4060007@cs.ntua.gr> I've been staring at the code of 'gen_event' and I cannot make much sense of how the code for swapping handlers works. In fact, I am quite convinced there is a bug in there but it is being silenced by the use of a catch. Can somebody please confirm that this is a bug or enlighten me on what's happening? The code of gen_event:do_swap/7 reads: do_swap(Mod1,Handler1,Args1,State1,Handler2,Args2,SName) -> %% finalise the existing handler State2 = do_terminate(...), {Mod2,Handler} = new_handler(Handler2, Handler1), %% <--- case catch Mod2:init({Args2, State2}) of {ok, State2a} -> {ok, Handler#handler{state = State2a}}; Other -> report_terminate(Handler2, crash, ...), %% <--- no end. Is the use of Handler2 correct in the lines identified as %% <--- ? At least one of them does not seem to be, but I cannot see which one. Kostis PS. This is not found by dialyzer - it requires very different analyses. From joelr1 Wed Oct 1 18:27:30 2008 From: joelr1 (Joel Reymont) Date: Wed, 1 Oct 2008 17:27:30 +0100 Subject: [erlang-questions] Erlang doesn't suck In-Reply-To: <48E3A1E6.4090307@alertlogic.net> References: <48E3A1E6.4090307@alertlogic.net> Message-ID: <9D9606A2-0064-471E-B214-9E82DC850982@gmail.com> On Oct 1, 2008, at 5:14 PM, Paul Fisher wrote: > Just curious about the config here. Was the solaris using 32 or 64- > bit erlang? Compiled with gcc, right? I believe I used 32 bits both on my Mac and at Joyent. Erlang (BEAM) emulator version 5.6.4 [source] [async-threads:0] [hipe] [kernel-poll:false] gcc -MM -MG -g -O2 ... Do I stand to gain anything from using 64 bits here? Thanks, Joel -- wagerlabs.com From kostis Wed Oct 1 18:58:00 2008 From: kostis (Kostis Sagonas) Date: Wed, 01 Oct 2008 19:58:00 +0300 Subject: [erlang-questions] Erlang doesn't suck In-Reply-To: References: Message-ID: <48E3AC18.2010700@cs.ntua.gr> Joel Reymont wrote: > Not once the pain goes away and only the results stick around. > > I spent a grueling 1+ week refactoring OpenPoker and wishing for > static typing. I started at number of git branches, only to be thrown > away a day or two later. Many were the times when I wished to tear my > hair out and throw Erlang far and away from my terrace ... Before you make yourself bald :-), you should probably read the following: http://user.it.uu.se/~kostis/Papers/wrangler.pdf It describes how you can get most of the benefits from static typing without static typing. Kostis From saleyn Wed Oct 1 19:03:43 2008 From: saleyn (Serge Aleynikov) Date: Wed, 01 Oct 2008 13:03:43 -0400 Subject: [erlang-questions] GTK bindings In-Reply-To: <48E0C70D.5020700@gmail.com> References: <48CF2F1B.3070003@lionet.info> <2ae3549f-f1cb-4e3c-b7e3-d805c6de372a@m36g2000hse.googlegroups.com> <48CFF05B.90401@lionet.info> <15b6a55b-956f-45c8-b412-76751fe630ab@e53g2000hsa.googlegroups.com> <087d239c-07b5-47ef-9372-ae097ca12bcd@m45g2000hsb.googlegroups.com> <3dbc6d1c0809161457v2ed4f29bxe16bcc124dbf06f5@mail.gmail.com> <14f0e3620809161547x32377a37ke4c9abee0a8c41e1@mail.gmail.com> <3dbc6d1c0809161643t33fb3a80l7cb4b330333a1ef7@mail.gmail.com> <4ac8254d0809170244s4ebd31b1y4d0b361cdf3cb76f@mail.gmail.com> <48D1FC87.8030601@it.uu.se> <48E0C70D.5020700@gmail.com> Message-ID: <48E3AD6F.5050909@gmail.com> I compiled the project and have been getting these errors at run-time. As a result the fonts are unreadable. Do you know how to switch font in the examples? =INFO REPORT==== 1-Oct-2008::12:51:27 === in: {gtknode,handle_portdata,2} portdata: "\n(gtknode:17066): Pango-WARNING **: failed to find shape engine, expect ugly output. engine-type='PangoRenderFc', script='latin'\n" =INFO REPORT==== 1-Oct-2008::12:51:27 === in: {gtknode,handle_portdata,2} portdata: "\n(gtknode:17066): Pango-WARNING **: failed to find shape engine, expect ugly output. engine-type='PangoRenderFc', script='common'\n" =INFO REPORT==== 1-Oct-2008::12:51:27 === in: {gtknode,handle_portdata,2} portdata: "\n(gtknode:17066): Pango-WARNING **: _pango_cairo_font_install called with bad font, expect ugly output\n" Mats Cronqvist wrote: > Richard Carlsson wrote: >> YourSurrogateGod wrote: >> >>> Speaking of GTK bindings. Are there any so that one could make Gnome >>> applications (use all of the widgets and such) with Erlang? I haven't >>> heard of any at the moment... >>> >> The most mature (and portable) alternative is probably WxErlang: >> http://www.erlang.org/~dgud/wxerlang/ >> http://sourceforge.net/projects/wxerlang/ >> > will, in all likelihood, eventually be bundled with OTP. > >> There are also a couple of attempts at direct GTK bindings, but >> don't know what their status is: >> >> http://code.google.com/p/gtknode/ >> > gtknode works fine on all versions of GTK from 2.4 to 2.12 (compiled > it last friday). > >> http://erlgtk.sourceforge.net/ > > dead AFAIK. > > mats > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From joelr1 Wed Oct 1 18:48:08 2008 From: joelr1 (Joel Reymont) Date: Wed, 1 Oct 2008 17:48:08 +0100 Subject: [erlang-questions] Erlang doesn't suck In-Reply-To: <48E3A86A.8010508@alertlogic.net> References: <48E3A1E6.4090307@alertlogic.net> <9D9606A2-0064-471E-B214-9E82DC850982@gmail.com> <48E3A86A.8010508@alertlogic.net> Message-ID: On Oct 1, 2008, at 5:42 PM, Paul Fisher wrote: > I would expect HIPE compiled stuff to have much more chance to go > faster, but otherwise it trades higher memory usage (64-bit > addresses in data structures) for larger addressable memory for a vm. I have yet to test using HiPE. > Which begs the question of whether you compile to native or not for > your benchmarking? Not everything benefits, but we have some > modules that show significant gains from: > > -compile([native, {hipe,[o3]}, inline]). I will test this next. That and further scaling on top of several VMs instead of one. -- wagerlabs.com From pfisher Wed Oct 1 18:42:18 2008 From: pfisher (Paul Fisher) Date: Wed, 01 Oct 2008 11:42:18 -0500 Subject: [erlang-questions] Erlang doesn't suck In-Reply-To: <9D9606A2-0064-471E-B214-9E82DC850982@gmail.com> References: <48E3A1E6.4090307@alertlogic.net> <9D9606A2-0064-471E-B214-9E82DC850982@gmail.com> Message-ID: <48E3A86A.8010508@alertlogic.net> Joel Reymont wrote: > On Oct 1, 2008, at 5:14 PM, Paul Fisher wrote: > >> Just curious about the config here. Was the solaris using 32 or 64- >> bit erlang? Compiled with gcc, right? > > > I believe I used 32 bits both on my Mac and at Joyent. > > Erlang (BEAM) emulator version 5.6.4 [source] [async-threads:0] [hipe] > [kernel-poll:false] > > gcc -MM -MG -g -O2 ... > > Do I stand to gain anything from using 64 bits here? I would expect HIPE compiled stuff to have much more chance to go faster, but otherwise it trades higher memory usage (64-bit addresses in data structures) for larger addressable memory for a vm. You don't seem to need to the memory, so only benefit i could see is gains from better HIPE code execution with the extra registers. Which begs the question of whether you compile to native or not for your benchmarking? Not everything benefits, but we have some modules that show significant gains from: -compile([native, {hipe,[o3]}, inline]). I really asked because we do have the potential to use the larger addressable memory space, so was curious on what your benchmarks were based. Unfortunately, I haven't had a chance to do direct comparisons between 32/64-bit vms yet... Thanks for sharing your experiences! -- paul From colm.dougan Wed Oct 1 19:31:20 2008 From: colm.dougan (Colm Dougan) Date: Wed, 1 Oct 2008 18:31:20 +0100 Subject: [erlang-questions] Multiple ETS lookups In-Reply-To: <8209f740809302326l4415b476vd82ed27cbed7b7ea@mail.gmail.com> References: <24d4f39c0809301831m6ca40d33id54979b468ad617@mail.gmail.com> <8209f740809302326l4415b476vd82ed27cbed7b7ea@mail.gmail.com> Message-ID: <24d4f39c0810011031p703c63apec7c0ec7b9670d86@mail.gmail.com> > 2008/10/1 Colm Dougan : >> Hi list, >> >> What do people think of the idea of adding a multiple ETS lookup >> function, analogous to the SQL 'IN' operator, where you can pass a >> list of keys and you get a list of matches? On Wed, Oct 1, 2008 at 7:26 AM, Ulf Wiger wrote: > I posted a slightly more general suggestion a while back: > > http://www.erlang.org/pipermail/erlang-questions/2007-May/026440.html That looks really useful. IMO there is room for both functions (seq and multi_lookup). In the first instance multi_lookup could be implemented in C but at a later date if your much more powerful seq stuff gets added then that may enable multi_lookup to be implemented in terms of seq. I'm happy to have a stab at putting together a patch for multi_lookup if there is any interest? I'm keen to know if people like the idea, don't like the idea or are indifferent to it :) Colm From saleyn Wed Oct 1 19:37:44 2008 From: saleyn (Serge Aleynikov) Date: Wed, 01 Oct 2008 13:37:44 -0400 Subject: [erlang-questions] GTK bindings In-Reply-To: <48E3AD6F.5050909@gmail.com> References: <48CF2F1B.3070003@lionet.info> <2ae3549f-f1cb-4e3c-b7e3-d805c6de372a@m36g2000hse.googlegroups.com> <48CFF05B.90401@lionet.info> <15b6a55b-956f-45c8-b412-76751fe630ab@e53g2000hsa.googlegroups.com> <087d239c-07b5-47ef-9372-ae097ca12bcd@m45g2000hsb.googlegroups.com> <3dbc6d1c0809161457v2ed4f29bxe16bcc124dbf06f5@mail.gmail.com> <14f0e3620809161547x32377a37ke4c9abee0a8c41e1@mail.gmail.com> <3dbc6d1c0809161643t33fb3a80l7cb4b330333a1ef7@mail.gmail.com> <4ac8254d0809170244s4ebd31b1y4d0b361cdf3cb76f@mail.gmail.com> <48D1FC87.8030601@it.uu.se> <48E0C70D.5020700@gmail.com> <48E3AD6F.5050909@gmail.com> Message-ID: <48E3B568.2010702@gmail.com> Actually I poked around with the makefile settings for gtknode and somehow the problem went away... Serge Aleynikov wrote: > I compiled the project and have been getting these errors at run-time. > As a result the fonts are unreadable. Do you know how to switch font in > the examples? > > =INFO REPORT==== 1-Oct-2008::12:51:27 === > in: {gtknode,handle_portdata,2} > portdata: "\n(gtknode:17066): Pango-WARNING **: failed to find > shape engine, expect ugly output. engine-type='PangoRenderFc', > script='latin'\n" > > =INFO REPORT==== 1-Oct-2008::12:51:27 === > in: {gtknode,handle_portdata,2} > portdata: "\n(gtknode:17066): Pango-WARNING **: failed to find > shape engine, expect ugly output. engine-type='PangoRenderFc', > script='common'\n" > > =INFO REPORT==== 1-Oct-2008::12:51:27 === > in: {gtknode,handle_portdata,2} > portdata: "\n(gtknode:17066): Pango-WARNING **: > _pango_cairo_font_install called with bad font, expect ugly output\n" > > > Mats Cronqvist wrote: >> Richard Carlsson wrote: >>> YourSurrogateGod wrote: >>> >>>> Speaking of GTK bindings. Are there any so that one could make Gnome >>>> applications (use all of the widgets and such) with Erlang? I haven't >>>> heard of any at the moment... >>>> >>> The most mature (and portable) alternative is probably WxErlang: >>> http://www.erlang.org/~dgud/wxerlang/ >>> http://sourceforge.net/projects/wxerlang/ >>> >> will, in all likelihood, eventually be bundled with OTP. >> >>> There are also a couple of attempts at direct GTK bindings, but >>> don't know what their status is: >>> >>> http://code.google.com/p/gtknode/ >>> >> gtknode works fine on all versions of GTK from 2.4 to 2.12 (compiled >> it last friday). >> >>> http://erlgtk.sourceforge.net/ >> dead AFAIK. >> >> mats >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions >> http://www.erlang.org/mailman/listinfo/erlang-questions >> > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From joelr1 Wed Oct 1 20:10:33 2008 From: joelr1 (Joel Reymont) Date: Wed, 1 Oct 2008 19:10:33 +0100 Subject: [erlang-questions] Erlang doesn't suck In-Reply-To: <48E3AC18.2010700@cs.ntua.gr> References: <48E3AC18.2010700@cs.ntua.gr> Message-ID: <01F5698E-8E44-4F29-8862-F3F073451E51@gmail.com> On Oct 1, 2008, at 5:58 PM, Kostis Sagonas wrote: > Before you make yourself bald :-), you should probably read the > following: > > http://user.it.uu.se/~kostis/Papers/wrangler.pdf Kostis, I'll give you the benefit of a doubt and ponder how Wrangler would have helped me switch from tuples to records everywhere in OpenPoker. I have a hunch that "typing things up" would have taken almost as long as the refactoring job itself. And then I would have had to retype everything again for records. I'll take static typing and type inference over dynamic typing almost any day of the week. -- wagerlabs.com From als Wed Oct 1 20:11:30 2008 From: als (Anthony Shipman) Date: Thu, 2 Oct 2008 04:11:30 +1000 Subject: [erlang-questions] typer bug? Message-ID: <200810020411.30133.als@iinet.net.au> I've got a recursive type specification. typer didn't seem to cope: > grep xmlNode */*l common/dwcConfig.erl:-spec loadConfig() -> {ok, xmlNode()} | {error, Reason::any()}. common/dwcConfig.erl:-spec toSimpleTree(xmlElement()) -> xmlNode(). common/dwcTypes.hrl:-type xmlNode() :: {Name::atom(), [{atom(), string()}], [xmlNode()]}. > typer --plt ../.erlang_plt -r . typer: analysis failed with error report: Unknown type xmlNode dwcConfig includes the dwcTypes.hrl file. -- Anthony Shipman Mamas don't let your babies als grow up to be outsourced. From ulf.wiger Wed Oct 1 20:17:55 2008 From: ulf.wiger (Ulf Wiger (TN/EAB)) Date: Wed, 01 Oct 2008 20:17:55 +0200 Subject: [erlang-questions] Erlang doesn't suck In-Reply-To: <01F5698E-8E44-4F29-8862-F3F073451E51@gmail.com> References: <48E3AC18.2010700@cs.ntua.gr> <01F5698E-8E44-4F29-8862-F3F073451E51@gmail.com> Message-ID: <48E3BED3.4020202@ericsson.com> Joel, The paper describes how Kostis applied Dialyzer and Typer to the wrangler source code and found some interesting stuff. It was a great talk at the workshop, Kostis. Thanks. BR, Ulf W Joel Reymont skrev: > On Oct 1, 2008, at 5:58 PM, Kostis Sagonas wrote: > >> Before you make yourself bald :-), you should probably read the >> following: >> >> http://user.it.uu.se/~kostis/Papers/wrangler.pdf > > > Kostis, > > I'll give you the benefit of a doubt and ponder how Wrangler would > have helped me switch from tuples to records everywhere in OpenPoker. > > I have a hunch that "typing things up" would have taken almost as long > as the refactoring job itself. And then I would have had to retype > everything again for records. > > I'll take static typing and type inference over dynamic typing almost > any day of the week. > > -- > wagerlabs.com > > > > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions From kostis Wed Oct 1 20:19:13 2008 From: kostis (Kostis Sagonas) Date: Wed, 01 Oct 2008 21:19:13 +0300 Subject: [erlang-questions] Erlang doesn't suck In-Reply-To: <01F5698E-8E44-4F29-8862-F3F073451E51@gmail.com> References: <48E3AC18.2010700@cs.ntua.gr> <01F5698E-8E44-4F29-8862-F3F073451E51@gmail.com> Message-ID: <48E3BF21.9090603@cs.ntua.gr> Joel Reymont wrote: > > On Oct 1, 2008, at 5:58 PM, Kostis Sagonas wrote: > >> Before you make yourself bald :-), you should probably read the >> following: >> >> http://user.it.uu.se/~kostis/Papers/wrangler.pdf > > > Kostis, > > I'll give you the benefit of a doubt and ponder how Wrangler would have > helped me switch from tuples to records everywhere in OpenPoker. The paper is *not* about Wrangler, refactoring or converting to records. Perhaps it's a good idea to read it first --- you might see its point... Kostis From mats.cronqvist Wed Oct 1 20:20:26 2008 From: mats.cronqvist (Mats Cronqvist) Date: Wed, 01 Oct 2008 20:20:26 +0200 Subject: [erlang-questions] GTK bindings In-Reply-To: <48E3B568.2010702@gmail.com> References: <48CF2F1B.3070003@lionet.info> <2ae3549f-f1cb-4e3c-b7e3-d805c6de372a@m36g2000hse.googlegroups.com> <48CFF05B.90401@lionet.info> <15b6a55b-956f-45c8-b412-76751fe630ab@e53g2000hsa.googlegroups.com> <087d239c-07b5-47ef-9372-ae097ca12bcd@m45g2000hsb.googlegroups.com> <3dbc6d1c0809161457v2ed4f29bxe16bcc124dbf06f5@mail.gmail.com> <14f0e3620809161547x32377a37ke4c9abee0a8c41e1@mail.gmail.com> <3dbc6d1c0809161643t33fb3a80l7cb4b330333a1ef7@mail.gmail.com> <4ac8254d0809170244s4ebd31b1y4d0b361cdf3cb76f@mail.gmail.com> <48D1FC87.8030601@it.uu.se> <48E0C70D.5020700@gmail.com> <48E3AD6F.5050909@gmail.com> <48E3B568.2010702@gmail.com> Message-ID: <48E3BF6A.50803@gmail.com> Serge Aleynikov wrote: > Actually I poked around with the makefile settings for gtknode and > somehow the problem went away... good thing, as i've never seen those errors... From als Wed Oct 1 19:10:12 2008 From: als (Anthony Shipman) Date: Thu, 2 Oct 2008 03:10:12 +1000 Subject: [erlang-questions] standard types for dialyzer Message-ID: <200810020310.12947.als@iinet.net.au> There are a lot of types for the stdlib and kernel functions. These should go into a single header file that all applications can include. Otherwise there can easily be clashes. For example I've defined a date() for my code but it clashes with "kernel/include/file.hrl" on the few occasions I include it. -- Anthony Shipman Mamas don't let your babies als grow up to be outsourced. From tty.erlang Wed Oct 1 20:34:07 2008 From: tty.erlang (t ty) Date: Wed, 1 Oct 2008 14:34:07 -0400 Subject: [erlang-questions] Erlang doesn't suck In-Reply-To: <48E3BED3.4020202@ericsson.com> References: <48E3AC18.2010700@cs.ntua.gr> <01F5698E-8E44-4F29-8862-F3F073451E51@gmail.com> <48E3BED3.4020202@ericsson.com> Message-ID: <290b3ba10810011134j1bec4347qbb7309075266a10f@mail.gmail.com> On Wed, Oct 1, 2008 at 2:17 PM, Ulf Wiger (TN/EAB) wrote: > > Joel, > > The paper describes how Kostis applied Dialyzer and > Typer to the wrangler source code and found some > interesting stuff. > > It was a great talk at the workshop, Kostis. Thanks. I agree. I consider this a must read paper from this year's workshop. t From joelr1 Wed Oct 1 20:49:24 2008 From: joelr1 (Joel Reymont) Date: Wed, 1 Oct 2008 19:49:24 +0100 Subject: [erlang-questions] Erlang doesn't suck In-Reply-To: <48E3BF21.9090603@cs.ntua.gr> References: <48E3AC18.2010700@cs.ntua.gr> <01F5698E-8E44-4F29-8862-F3F073451E51@gmail.com> <48E3BF21.9090603@cs.ntua.gr> Message-ID: On Oct 1, 2008, at 7:19 PM, Kostis Sagonas wrote: > The paper is *not* about Wrangler, refactoring or converting to > records. > Perhaps it's a good idea to read it first --- you might see its > point... I skimmed the paper before replying. The paper is about using Dialyzer on Wrangler. The point that I'm trying to make is that I think Dialyzer would have helped me convert from tuples to records. -- wagerlabs.com From joelr1 Wed Oct 1 20:51:39 2008 From: joelr1 (Joel Reymont) Date: Wed, 1 Oct 2008 19:51:39 +0100 Subject: [erlang-questions] Building 64-bit Erlang on Solaris 11 Message-ID: <11584396-2118-469C-88DA-B234E10130CA@gmail.com> ./configure --prefix=/opt/local --enable-64bit CFLAGS='-m64' ... gmake ... ld: fatal: file obj/i386-pc-solaris2.11/opt/plain/erl_main.o: wrong ELF class: ELFCLASS64 ld: fatal: File processing errors. No output written to /home/admin/ otp_src_R12B-4/bin/i386-pc-solaris2.11/beam What am I doing wrong? Thanks, Joel P.S. Omitting CFLAGS='-m64' builds a 32-bit Erlang. -- wagerlabs.com From joelr1 Wed Oct 1 20:53:29 2008 From: joelr1 (Joel Reymont) Date: Wed, 1 Oct 2008 19:53:29 +0100 Subject: [erlang-questions] Erlang doesn't suck In-Reply-To: <48E3A86A.8010508@alertlogic.net> References: <48E3A1E6.4090307@alertlogic.net> <9D9606A2-0064-471E-B214-9E82DC850982@gmail.com> <48E3A86A.8010508@alertlogic.net> Message-ID: <28B99EDD-C840-4E3F-B59C-77A89F371B12@gmail.com> On Oct 1, 2008, at 5:42 PM, Paul Fisher wrote: > Which begs the question of whether you compile to native or not for > your benchmarking? Not everything benefits, but we have some > modules that show significant gains from: > > -compile([native, {hipe,[o3]}, inline]). There's certainly an increase in throughput (request per second) with hipe, even under 32 bits. Is there a way to mass-hipe-compile all of OTP? Simulating gameplay with 3000 games... Waiting for games to end... ... =INFO REPORT==== 1-Oct-2008::18:15:35 === requests: 40041 bytes: 736492 requests_per_second: 1334 bytes_per_second: 24549 50 games finished ... 1250 games finished ... =INFO REPORT==== 1-Oct-2008::18:16:06 === requests: 48419 bytes: 543775 requests_per_second: 1611 bytes_per_second: 18100 ... 3000 games finished =INFO REPORT==== 1-Oct-2008::18:16:35 === requests: 39604 bytes: 345976 requests_per_second: 1319 bytes_per_second: 11529 Elapsed: 62.517129s, Average run time: 0.020839043 seconds Now I have to try to compile R12B4 in 64-bit mode.... -- wagerlabs.com From erlang-questions_efine Wed Oct 1 21:42:00 2008 From: erlang-questions_efine (Edwin Fine) Date: Wed, 1 Oct 2008 15:42:00 -0400 Subject: [erlang-questions] Erlang doesn't suck In-Reply-To: <28B99EDD-C840-4E3F-B59C-77A89F371B12@gmail.com> References: <48E3A1E6.4090307@alertlogic.net> <9D9606A2-0064-471E-B214-9E82DC850982@gmail.com> <48E3A86A.8010508@alertlogic.net> <28B99EDD-C840-4E3F-B59C-77A89F371B12@gmail.com> Message-ID: <6c2563b20810011242k12b0375bjfbaba3a02f0f29c6@mail.gmail.com> I have not measured it in this specific instance, so I may be wrong, but I don't think you will get a net increase in performance from 64 bit code (compared to 32 bits on the same processor). In almost every case that I can think of where I have used both, the 32 bit code was on average faster and (unsurprisingly) smaller. Where 64 bits won was when lots of memory was needed and available for use. Maybe if the code had optimizations for the 64 bit processor which included some faster instructions that were specific to the 64-bit mode, and a nice fat register set to avoid passing parameters on the stack, it could be faster. I am very curious: has anyone taken any performance measurements of real-world applications in 32 bit vs 64 bit Erlang on the same processor configuration? As for compilation failures you are seeing, I would try setting the following: export LDFLAGS="-m64 $LDFLAGS" export CFLAGS="-m64 $CFLAGS" The LDFLAGS is needed so that the build doesn't try to link with 32-bit objects. On Wed, Oct 1, 2008 at 2:53 PM, Joel Reymont wrote: > > On Oct 1, 2008, at 5:42 PM, Paul Fisher wrote: > > > Which begs the question of whether you compile to native or not for > > your benchmarking? Not everything benefits, but we have some > > modules that show significant gains from: > > > > -compile([native, {hipe,[o3]}, inline]). > > > There's certainly an increase in throughput (request per second) with > hipe, even under 32 bits. > > Is there a way to mass-hipe-compile all of OTP? > > Simulating gameplay with 3000 games... > Waiting for games to end... > ... > =INFO REPORT==== 1-Oct-2008::18:15:35 === > requests: 40041 > bytes: 736492 > requests_per_second: 1334 > bytes_per_second: 24549 > 50 games finished > ... > 1250 games finished > ... > =INFO REPORT==== 1-Oct-2008::18:16:06 === > requests: 48419 > bytes: 543775 > requests_per_second: 1611 > bytes_per_second: 18100 > ... > 3000 games finished > > =INFO REPORT==== 1-Oct-2008::18:16:35 === > requests: 39604 > bytes: 345976 > requests_per_second: 1319 > bytes_per_second: 11529 > > Elapsed: 62.517129s, Average run time: 0.020839043 seconds > > Now I have to try to compile R12B4 in 64-bit mode.... > > > -- > wagerlabs.com > > > > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081001/24029ac7/attachment.html From joelr1 Wed Oct 1 21:48:02 2008 From: joelr1 (Joel Reymont) Date: Wed, 1 Oct 2008 20:48:02 +0100 Subject: [erlang-questions] Erlang doesn't suck In-Reply-To: <6c2563b20810011242k12b0375bjfbaba3a02f0f29c6@mail.gmail.com> References: <48E3A1E6.4090307@alertlogic.net> <9D9606A2-0064-471E-B214-9E82DC850982@gmail.com> <48E3A86A.8010508@alertlogic.net> <28B99EDD-C840-4E3F-B59C-77A89F371B12@gmail.com> <6c2563b20810011242k12b0375bjfbaba3a02f0f29c6@mail.gmail.com> Message-ID: <2EE20B52-57F9-4E66-AE53-EA4544E7FF07@gmail.com> On Oct 1, 2008, at 8:42 PM, Edwin Fine wrote: > As for compilation failures you are seeing, I would try setting the > following: > > export LDFLAGS="-m64 $LDFLAGS" > export CFLAGS="-m64 $CFLAGS" Did the above and then ./configure --prefix=/opt/local --enable-64bit ... gmake clean && gmake ... ld: warning: file /home/admin/otp_src_R12B-4/erts/emulator/zlib/obj/ i386-pc-solaris2.11/opt/libz.a(adler32.o): wrong ELF class: ELFCLASS32 ld: warning: file /home/admin/otp_src_R12B-4/erts/emulator/pcre/obj/ i386-pc-solaris2.11/opt/libepcre.a(pcre_compile.o): wrong ELF class: ELFCLASS32 Undefined first referenced symbol in file inflate obj/i386-pc-solaris2.11/opt/plain/ gzio.o crc32 obj/i386-pc-solaris2.11/opt/plain/ erl_bif_ch -- wagerlabs.com From pfisher Wed Oct 1 21:54:18 2008 From: pfisher (Paul Fisher) Date: Wed, 01 Oct 2008 14:54:18 -0500 Subject: [erlang-questions] Building 64-bit Erlang on Solaris 11 In-Reply-To: <11584396-2118-469C-88DA-B234E10130CA@gmail.com> References: <11584396-2118-469C-88DA-B234E10130CA@gmail.com> Message-ID: <48E3D56A.4060807@alertlogic.net> Joel Reymont wrote: > ./configure --prefix=/opt/local --enable-64bit CFLAGS='-m64' > ... > gmake > ... > ld: fatal: file obj/i386-pc-solaris2.11/opt/plain/erl_main.o: wrong > ELF class: ELFCLASS64 > ld: fatal: File processing errors. No output written to /home/admin/ > otp_src_R12B-4/bin/i386-pc-solaris2.11/beam > > What am I doing wrong? > > Thanks, Joel > > P.S. Omitting CFLAGS='-m64' builds a 32-bit Erlang. Not so straight forward (esp. if you use linked in drivers as we do). Here is what it takes First this patch: This patch allows 64-bit builds when the target system supports both 32-bit and 64-bit in the same system environment. Specifically, this works on Solaris 10/Opensolaris, and adjusts the --enable-darwin-64-bit configure flag to be simply --enable-64bit so that it can be used for the same purpose on both darwin and solaris (building 64-bit target environment) without having to introduce another system specific configure flag. This cleanly builds with the following configure command line: ~/bld/otp_src_R12B-3$ CFLAGS='-m64' LDFLAGS='-m64' ./configure \ --enable-threads \ --enable-smp-support --enable-kernel-poll --enable-hipe \ --disable-megaco-flex-scanner-drvlineno --without-odbc \ --enable-64bit on: ~/bld/otp_src_R12B-3$ uname -a SunOS pfisher-laptop 5.11 snv_94 i86pc i386 i86pc Solaris This does not fix common_test, which seems to be in its own world, and I'll send another patch for that. For now I just set it to SKIP. diff -ru otp_src_R12B-4/configure otp_src_R12B-4.64bit/configure --- otp_src_R12B-4/configure 2008-09-02 13:03:59.000000000 -0500 +++ otp_src_R12B-4.64bit/configure 2008-10-01 14:20:07.448422739 -0500 @@ -814,7 +814,7 @@ --enable-dynamic-ssl-lib force using dynamic openssl libraries --disable-erlang-mandir do not install Erlang man pages in a private directory --enable-darwin-universal build universal binaries on darwin i386 - --enable-darwin-64bit build 64bit binaries on darwin + --enable-64bit build 64bit binaries on 32/64 capable systems Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] @@ -2645,23 +2645,23 @@ fi; -# Check whether --enable-darwin-64bit or --disable-darwin-64bit was given. -if test "${enable_darwin_64bit+set}" = set; then - enableval="$enable_darwin_64bit" +# Check whether --enable-64bit or --disable-64bit was given. +if test "${enable_64bit+set}" = set; then + enableval="$enable_64bit" case "$enableval" in - no) enable_darwin_64bit=no ;; - *) enable_darwin_64bit=yes ;; + no) enable_64bit=no ;; + *) enable_64bit=yes ;; esac else - enable_darwin_64bit=no + enable_64bit=no fi; TMPSYS=`uname -s`-`uname -m` if test X${enable_darwin_universal} = Xyes; then - if test X${enable_darwin_64bit} = Xyes; then + if test X${enable_64bit} = Xyes; then { { echo "$as_me:$LINENO: error: --enable-darwin-universal and --enable-darwin-64bit mutually exclusive" >&5 -echo "$as_me: error: --enable-darwin-universal and --enable-darwin-64bit mutually exclusive" >&2;} +echo "$as_me: error: --enable-darwin-universal and --enable-64bit mutually exclusive" >&2;} { (exit 1); exit 1; }; } fi enable_hipe=no @@ -2670,17 +2670,39 @@ LDFLAGS="-arch i386 -arch ppc $LDFLAGS" export LDFLAGS fi -if test X${enable_darwin_64bit} = Xyes; then - if test X"$TMPSYS" '!=' X"Darwin-i386"; then - { { echo "$as_me:$LINENO: error: --enable-darwin-64bit only supported on x86 host" >&5 -echo "$as_me: error: --enable-darwin-64bit only supported on x86 host" >&2;} - { (exit 1); exit 1; }; } - fi - enable_hipe=no - CFLAGS="-m64 $CFLAGS" - export CFLAGS - LDFLAGS="-m64 $LDFLAGS" - export LDFLAGS +if test X${enable_64bit} = Xyes; then + case $TMPSYS in + Darwin-i386) + enable_hipe=no + CFLAGS="-m64 $CFLAGS" + export CFLAGS + LDFLAGS="-m64 $LDFLAGS" + export LDFLAGS + ;; + SunOS-i86pc) + case $CFLAGS in + *-m64*) + ;; + *) + CFLAGS="-m64 $CFLAGS" + export CLAGS + ;; + esac + case $LDLAGS in + *-m64*) + ;; + *) + LDLAGS="-m64 $LDLAGS" + export LDLAGS + ;; + esac + ;; + + *) + echo "$as_me: error: --enable-64bit only supported on x86 host" + exit 1 + ;; + esac fi export ERL_TOP diff -ru otp_src_R12B-4/configure.in otp_src_R12B-4.64bit/configure.in --- otp_src_R12B-4/configure.in 2008-06-10 07:47:35.000000000 -0500 +++ otp_src_R12B-4.64bit/configure.in 2008-10-01 14:19:13.437109172 -0500 @@ -179,20 +179,20 @@ ],enable_darwin_universal=no) -AC_ARG_ENABLE(darwin-64bit, -[ --enable-darwin-64bit build 64bit binaries on darwin], +AC_ARG_ENABLE(64bit, +[ --enable-64bit build 64bit binaries on 32/64 bit capable system], [ case "$enableval" in - no) enable_darwin_64bit=no ;; - *) enable_darwin_64bit=yes ;; + no) enable_64bit=no ;; + *) enable_64bit=yes ;; esac -],enable_darwin_64bit=no) +],enable_64bit=no) dnl OK, we might have darwin switches off different kinds, lets dnl check it all before continuing. TMPSYS=`uname -s`-`uname -m` if test X${enable_darwin_universal} = Xyes; then if test X${enable_darwin_64bit} = Xyes; then - AC_MSG_ERROR([--enable-darwin-universal and --enable-darwin-64bit mutually exclusive]) + AC_MSG_ERROR([--enable-darwin-universal and --enable-64bit mutually exclusive]) fi enable_hipe=no CFLAGS="-arch i386 -arch ppc $CFLAGS" @@ -200,15 +200,39 @@ LDFLAGS="-arch i386 -arch ppc $LDFLAGS" export LDFLAGS fi -if test X${enable_darwin_64bit} = Xyes; then - if test X"$TMPSYS" '!=' X"Darwin-i386"; then - AC_MSG_ERROR([--enable-darwin-64bit only supported on x86 host]) - fi - enable_hipe=no - CFLAGS="-m64 $CFLAGS" - export CFLAGS - LDFLAGS="-m64 $LDFLAGS" - export LDFLAGS +if test X${enable_64bit} = Xyes; then + case $TMPSYS in + Darwin-i386) + enable_hipe=no + CFLAGS="-m64 $CFLAGS" + export CFLAGS + LDFLAGS="-m64 $LDFLAGS" + export LDFLAGS + ;; + SunOS-i86pc) + case $CFLAGS in + *-m64*) + ;; + *) + CFLAGS="-m64 $CFLAGS" + export CLAGS + ;; + esac + case $LDLAGS in + *-m64*) + ;; + *) + LDLAGS="-m64 $LDLAGS" + export LDLAGS + ;; + esac + ;; + + *) + echo "$as_me: error: --enable-64bit only supported on x86 host" + exit 1 + ;; + esac fi export ERL_TOP diff -ru otp_src_R12B-4/erts/configure otp_src_R12B-4.64bit/erts/configure --- otp_src_R12B-4/erts/configure 2008-09-02 13:03:54.000000000 -0500 +++ otp_src_R12B-4.64bit/erts/configure 2008-10-01 14:17:36.145321678 -0500 @@ -863,7 +863,7 @@ --enable-elib-malloc use elib_malloc instead of normal malloc --enable-fp-exceptions Use hardware floating point exceptions (default if hipe enabled) --enable-darwin-universal build universal binaries on darwin i386 - --enable-darwin-64bit build 64bit binaries on darwin + --enable-64bit build 64bit binaries on 32/64 capable system --disable-fixalloc disable the use of fix_alloc --enable-clock-gettime Use clock-gettime for time correction --enable-native-ethr-impls enable native ethread implementations @@ -2665,16 +2665,16 @@ fi; -# Check whether --enable-darwin-64bit or --disable-darwin-64bit was given. -if test "${enable_darwin_64bit+set}" = set; then - enableval="$enable_darwin_64bit" +# Check whether --enable-64bit or --disable-64bit was given. +if test "${enable_64bit+set}" = set; then + enableval="$enable_64bit" case "$enableval" in - no) enable_darwin_64bit=no ;; - *) enable_darwin_64bit=yes ;; + no) enable_64bit=no ;; + *) enable_64bit=yes ;; esac else - enable_darwin_64bit=no + enable_64bit=no fi; @@ -2755,9 +2755,9 @@ TMPSYS=`uname -s`-`uname -m` if test X${enable_darwin_universal} = Xyes; then - if test X${enable_darwin_64bit} = Xyes; then - { { echo "$as_me:$LINENO: error: --enable-darwin-universal and --enable-darwin-64bit mutually exclusive" >&5 -echo "$as_me: error: --enable-darwin-universal and --enable-darwin-64bit mutually exclusive" >&2;} + if test X${enable_64bit} = Xyes; then + { { echo "$as_me:$LINENO: error: --enable-darwin-universal and --enable-64bit mutually exclusive" >&5 +echo "$as_me: error: --enable-darwin-universal and --enable-64bit mutually exclusive" >&2;} { (exit 1); exit 1; }; } fi enable_hipe=no @@ -2776,20 +2776,35 @@ ;; esac fi -if test X${enable_darwin_64bit} = Xyes; then - if test X"$TMPSYS" '!=' X"Darwin-i386"; then - { { echo "$as_me:$LINENO: error: --enable-darwin-64bit only supported on x86 host" >&5 -echo "$as_me: error: --enable-darwin-64bit only supported on x86 host" >&2;} - { (exit 1); exit 1; }; } - fi - enable_hipe=no - case $CFLAGS in +if test X${enable_64bit} = Xyes; then + case $TMPSYS in + Darwin-i386) + enable_hipe=no + case $CFLAGS in *-m64*) ;; *) CFLAGS="-m64 $CFLAGS" + export CLAGS ;; - esac + esac + ;; + SunOS-i86pc) + case $CFLAGS in + *-m64*) + ;; + *) + CFLAGS="-m64 $CFLAGS" + export CLAGS + ;; + esac + ;; + + *) + echo "$as_me: error: --enable-64bit only supported on x86 host" + exit 1 + ;; + esac fi @@ -4716,6 +4731,17 @@ esac fi ;; + amd64-sol2*) + { echo "$as_me:$LINENO: Adjusting LDFLAGS to cope with 64bit SunOS" >&5 +echo "$as_me: Adjusting LDFLAGS to cope with 64bit SunOS" >&6;} + case $LDFLAGS in + *-m64*) + ;; + *) + LDFLAGS="-m64 $LDFLAGS" + ;; + esac + ;; esac @@ -20430,7 +20456,19 @@ DED_LD_FLAG_RUNTIME_LIBRARY_PATH= ;; solaris2*|sysv4*) + DED_LD=$CC DED_LDFLAGS="-G" + case $CC in + gcc) + DED_LDFLAGS="-shared $DED_LDFLAGS" + ;; + esac + case $ARCH in + amd64) + DED_LDFLAGS="-m64 $DED_LDFLAGS" + DED_CFLAGS="-m64 $DED_CFLAGS" + ;; + esac ;; aix4*) DED_LDFLAGS="-G -bnoentry -bexpall" diff -ru otp_src_R12B-4/erts/configure.in otp_src_R12B-4.64bit/erts/configure.in --- otp_src_R12B-4/erts/configure.in 2008-09-01 07:51:17.000000000 -0500 +++ otp_src_R12B-4.64bit/erts/configure.in 2008-10-01 14:17:39.750396425 -0500 @@ -172,13 +172,13 @@ ],enable_darwin_universal=no) -AC_ARG_ENABLE(darwin-64bit, -[ --enable-darwin-64bit build 64bit binaries on darwin], +AC_ARG_ENABLE(64bit, +[ --enable-64bit build 64bit binaries on 32/64 capable system], [ case "$enableval" in - no) enable_darwin_64bit=no ;; - *) enable_darwin_64bit=yes ;; + no) enable_64bit=no ;; + *) enable_64bit=yes ;; esac -],enable_darwin_64bit=no) +],enable_64bit=no) AC_ARG_ENABLE(fixalloc, @@ -239,8 +239,8 @@ dnl check it all before continuing. TMPSYS=`uname -s`-`uname -m` if test X${enable_darwin_universal} = Xyes; then - if test X${enable_darwin_64bit} = Xyes; then - AC_MSG_ERROR([--enable-darwin-universal and --enable-darwin-64bit mutually exclusive]) + if test X${enable_64bit} = Xyes; then + AC_MSG_ERROR([--enable-darwin-universal and --enable-64bit mutually exclusive]) fi enable_hipe=no case $CFLAGS in @@ -258,18 +258,35 @@ ;; esac fi -if test X${enable_darwin_64bit} = Xyes; then - if test X"$TMPSYS" '!=' X"Darwin-i386"; then - AC_MSG_ERROR([--enable-darwin-64bit only supported on x86 host]) - fi - enable_hipe=no - case $CFLAGS in +if test X${enable_64bit} = Xyes; then + case $TMPSYS in + Darwin-i386) + enable_hipe=no + case $CFLAGS in *-m64*) ;; *) CFLAGS="-m64 $CFLAGS" + export CLAGS ;; - esac + esac + ;; + SunOS-i86pc) + case $CFLAGS in + *-m64*) + ;; + *) + CFLAGS="-m64 $CFLAGS" + export CLAGS + ;; + esac + ;; + + *) + echo "$as_me: error: --enable-64bit only supported on x86 host" + exit 1 + ;; + esac fi @@ -494,10 +511,10 @@ dnl has a build/configure system re rx-lib that is not compatible dnl First remove common_tests skip file. -dnl Adjust LDFLAGS to allow 64bit linkage on DARWIN +dnl Adjust LDFLAGS to allow 64bit linkage on 32/64 system case $ARCH-$OPSYS in - amd64-darwin*) - AC_MSG_NOTICE([Adjusting LDFLAGS to cope with 64bit Darwin]) + amd64-darwin*|amd64-sol2*) + AC_MSG_NOTICE([Adjusting LDFLAGS to cope with 64bit system]) case $LDFLAGS in *-m64*) ;; @@ -526,6 +543,17 @@ esac fi ;; + amd64-sol2*) + { echo "$as_me:$LINENO: Adjusting LDFLAGS to cope with 64bit SunOS" >&5 +echo "$as_me: Adjusting LDFLAGS to cope with 64bit SunOS" >&6;} + case $LDFLAGS in + *-m64*) + ;; + *) + LDFLAGS="-m64 $LDFLAGS" + ;; + esac + ;; esac @@ -2732,7 +2760,19 @@ DED_LD_FLAG_RUNTIME_LIBRARY_PATH= ;; solaris2*|sysv4*) + DED_LD=$CC DED_LDFLAGS="-G" + case $CC in + gcc) + DED_LDFLAGS="-shared $DED_LDFLAGS" + ;; + esac + case $ARCH in + amd64) + DED_LDFLAGS="-m64 $DED_LDFLAGS" + DED_CFLAGS="-m64 $DED_CFLAGS" + ;; + esac ;; aix4*) DED_LDFLAGS="-G -bnoentry -bexpall" Then a script that configures and builds stuff (the skip of common_test is important, others are just to avoid building them): #!/usr/bin/env bash set -e cd otp_src_R12B-4 CFLAGS='-m64' LDFLAGS='-m64' LIBS='-lumem' ./configure --enable-threads --enable-smp-support --enable-kernel-poll --enable-hipe --disable-megaco-flex-scanner-drvlineno --without-unixodbc --enable-64bit touch lib/common_test/SKIP touch lib/cosEvent/SKIP touch lib/cosEventDomain/SKIP touch lib/cosFileTransfer/SKIP touch lib/cosNotification/SKIP touch lib/cosProperty/SKIP touch lib/cosTime/SKIP touch lib/cosTransactions/SKIP touch lib/megaco/SKIP touch lib/odbc/SKIP touch lib/orber/SKIP make pfexec make install -- paul From erlang-questions_efine Wed Oct 1 22:27:11 2008 From: erlang-questions_efine (Edwin Fine) Date: Wed, 1 Oct 2008 16:27:11 -0400 Subject: [erlang-questions] Erlang doesn't suck In-Reply-To: <2EE20B52-57F9-4E66-AE53-EA4544E7FF07@gmail.com> References: <48E3A1E6.4090307@alertlogic.net> <9D9606A2-0064-471E-B214-9E82DC850982@gmail.com> <48E3A86A.8010508@alertlogic.net> <28B99EDD-C840-4E3F-B59C-77A89F371B12@gmail.com> <6c2563b20810011242k12b0375bjfbaba3a02f0f29c6@mail.gmail.com> <2EE20B52-57F9-4E66-AE53-EA4544E7FF07@gmail.com> Message-ID: <6c2563b20810011327i120c30f3sc5a5ac82903c88ba@mail.gmail.com> Looks like Paul Fisher has it nailed :) On Wed, Oct 1, 2008 at 3:48 PM, Joel Reymont wrote: > > On Oct 1, 2008, at 8:42 PM, Edwin Fine wrote: > > As for compilation failures you are seeing, I would try setting the >> following: >> >> export LDFLAGS="-m64 $LDFLAGS" >> export CFLAGS="-m64 $CFLAGS" >> > > > Did the above and then > > ./configure --prefix=/opt/local --enable-64bit > ... > gmake clean && gmake > ... > ld: warning: file > /home/admin/otp_src_R12B-4/erts/emulator/zlib/obj/i386-pc-solaris2.11/opt/libz.a(adler32.o): > wrong ELF class: ELFCLASS32 > ld: warning: file > /home/admin/otp_src_R12B-4/erts/emulator/pcre/obj/i386-pc-solaris2.11/opt/libepcre.a(pcre_compile.o): > wrong ELF class: ELFCLASS32 > Undefined first referenced > symbol in file > inflate > obj/i386-pc-solaris2.11/opt/plain/gzio.o > crc32 > obj/i386-pc-solaris2.11/opt/plain/erl_bif_ch > > -- > wagerlabs.com > > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081001/324e3123/attachment.html From kostis Wed Oct 1 22:57:45 2008 From: kostis (Kostis Sagonas) Date: Wed, 01 Oct 2008 23:57:45 +0300 Subject: [erlang-questions] Erlang doesn't suck In-Reply-To: <290b3ba10810011134j1bec4347qbb7309075266a10f@mail.gmail.com> References: <48E3AC18.2010700@cs.ntua.gr> <01F5698E-8E44-4F29-8862-F3F073451E51@gmail.com> <48E3BED3.4020202@ericsson.com> <290b3ba10810011134j1bec4347qbb7309075266a10f@mail.gmail.com> Message-ID: <48E3E449.9090509@cs.ntua.gr> t ty wrote: > On Wed, Oct 1, 2008 at 2:17 PM, Ulf Wiger (TN/EAB) > wrote: >> Joel, >> >> The paper describes how Kostis applied Dialyzer and >> Typer to the wrangler source code and found some >> interesting stuff. >> >> It was a great talk at the workshop, Kostis. Thanks. > > I agree. I consider this a must read paper from this year's workshop. Thank you both for your compliments. I admit that I enjoyed very much both writing the paper and giving the talk at the workshop. For the record, I guess, the paper is not just a case study. It aims to describe a *methodology* on how to gradually type a non-trivial existing Erlang application and the benefits of doing so. Comments welcome! Kostis From kostis Wed Oct 1 23:00:47 2008 From: kostis (Kostis Sagonas) Date: Thu, 02 Oct 2008 00:00:47 +0300 Subject: [erlang-questions] Erlang doesn't suck In-Reply-To: <28B99EDD-C840-4E3F-B59C-77A89F371B12@gmail.com> References: <48E3A1E6.4090307@alertlogic.net> <9D9606A2-0064-471E-B214-9E82DC850982@gmail.com> <48E3A86A.8010508@alertlogic.net> <28B99EDD-C840-4E3F-B59C-77A89F371B12@gmail.com> Message-ID: <48E3E4FF.3020403@cs.ntua.gr> Joel Reymont wrote: > On Oct 1, 2008, at 5:42 PM, Paul Fisher wrote: > > There's certainly an increase in throughput (request per second) with > hipe, even under 32 bits. > > Is there a way to mass-hipe-compile all of OTP? Not an easy one that I know of. We have discussed many times with the OTP folks the possibility to add such a configure option, but so far it has not happened. Yet another item for the upcoming meeting with them. Perhaps this option will be available in R12B-5. Kostis From kostis Wed Oct 1 23:03:30 2008 From: kostis (Kostis Sagonas) Date: Thu, 02 Oct 2008 00:03:30 +0300 Subject: [erlang-questions] typer bug? In-Reply-To: <200810020411.30133.als@iinet.net.au> References: <200810020411.30133.als@iinet.net.au> Message-ID: <48E3E5A2.1070906@cs.ntua.gr> Anthony Shipman wrote: > I've got a recursive type specification. typer didn't seem to cope: User-defined recursive types are currently not supported. This is on our TODO list but I doubt it will happen soon. Sorry about that, Kostis From saleyn Thu Oct 2 01:43:08 2008 From: saleyn (Serge Aleynikov) Date: Wed, 01 Oct 2008 19:43:08 -0400 Subject: [erlang-questions] GTK bindings In-Reply-To: <48E3BF6A.50803@gmail.com> References: <48CF2F1B.3070003@lionet.info> <2ae3549f-f1cb-4e3c-b7e3-d805c6de372a@m36g2000hse.googlegroups.com> <48CFF05B.90401@lionet.info> <15b6a55b-956f-45c8-b412-76751fe630ab@e53g2000hsa.googlegroups.com> <087d239c-07b5-47ef-9372-ae097ca12bcd@m45g2000hsb.googlegroups.com> <3dbc6d1c0809161457v2ed4f29bxe16bcc124dbf06f5@mail.gmail.com> <14f0e3620809161547x32377a37ke4c9abee0a8c41e1@mail.gmail.com> <3dbc6d1c0809161643t33fb3a80l7cb4b330333a1ef7@mail.gmail.com> <4ac8254d0809170244s4ebd31b1y4d0b361cdf3cb76f@mail.gmail.com> <48D1FC87.8030601@it.uu.se> <48E0C70D.5020700@gmail.com> <48E3AD6F.5050909@gmail.com> <48E3B568.2010702@gmail.com> <48E3BF6A.50803@gmail.com> Message-ID: <48E40B0C.4050509@gmail.com> BTW, the top example seems pretty sluggish at responding to grid row updates. Is there a way to ensure that updating the grid & repainting doesn't flicker the screen? Mats Cronqvist wrote: > Serge Aleynikov wrote: >> Actually I poked around with the makefile settings for gtknode and >> somehow the problem went away... > good thing, as i've never seen those errors... > From yoursurrogategod Thu Oct 2 04:53:33 2008 From: yoursurrogategod (YourSurrogateGod) Date: Wed, 1 Oct 2008 19:53:33 -0700 (PDT) Subject: [erlang-questions] GTK bindings In-Reply-To: <48E3B568.2010702@gmail.com> References: <48CF2F1B.3070003@lionet.info> <2ae3549f-f1cb-4e3c-b7e3-d805c6de372a@m36g2000hse.googlegroups.com> <48CFF05B.90401@lionet.info> <15b6a55b-956f-45c8-b412-76751fe630ab@e53g2000hsa.googlegroups.com> <087d239c-07b5-47ef-9372-ae097ca12bcd@m45g2000hsb.googlegroups.com> <3dbc6d1c0809161457v2ed4f29bxe16bcc124dbf06f5@mail.gmail.com> <14f0e3620809161547x32377a37ke4c9abee0a8c41e1@mail.gmail.com> <3dbc6d1c0809161643t33fb3a80l7cb4b330333a1ef7@mail.gmail.com> <4ac8254d0809170244s4ebd31b1y4d0b361cdf3cb76f@mail.gmail.com> <48D1FC87.8030601@it.uu.se> <48E0C70D.5020700@gmail.com> <48E3AD6F.5050909@gmail.com> <48E3B568.2010702@gmail.com> Message-ID: <68918cba-a4cd-45bd-a47b-50684819ca16@m45g2000hsb.googlegroups.com> Could you please show your Makefile? On Oct 1, 1:37?pm, Serge Aleynikov wrote: > Actually I poked around with the makefile settings for gtknode and > somehow the problem went away... > > > > > > Serge Aleynikov wrote: > > I compiled the project and have been getting these errors at run-time. > > As a result the fonts are unreadable. ?Do you know how to switch font in > > the examples? > > > =INFO REPORT==== 1-Oct-2008::12:51:27 === > > ? ? ?in: {gtknode,handle_portdata,2} > > ? ? ?portdata: "\n(gtknode:17066): Pango-WARNING **: failed to find > > shape engine, expect ugly output. engine-type='PangoRenderFc', > > script='latin'\n" > > > =INFO REPORT==== 1-Oct-2008::12:51:27 === > > ? ? ?in: {gtknode,handle_portdata,2} > > ? ? ?portdata: "\n(gtknode:17066): Pango-WARNING **: failed to find > > shape engine, expect ugly output. engine-type='PangoRenderFc', > > script='common'\n" > > > =INFO REPORT==== 1-Oct-2008::12:51:27 === > > ? ? ?in: {gtknode,handle_portdata,2} > > ? ? ?portdata: "\n(gtknode:17066): Pango-WARNING **: > > _pango_cairo_font_install called with bad font, expect ugly output\n" > > > Mats Cronqvist wrote: > >> Richard Carlsson wrote: > >>> YourSurrogateGod wrote: > > >>>> Speaking of GTK bindings. Are there any so that one could make Gnome > >>>> applications (use all of the widgets and such) with Erlang? I haven't > >>>> heard of any at the moment... > > >>> The most mature (and portable) alternative is probably WxErlang: > >>>http://www.erlang.org/~dgud/wxerlang/ > >>>http://sourceforge.net/projects/wxerlang/ > > >> ? will, in all likelihood, eventually be bundled with OTP. > > >>> There are also a couple of attempts at direct GTK bindings, but > >>> don't know what their status is: > > >>>http://code.google.com/p/gtknode/ > > >> ? gtknode works fine on all versions of GTK from 2.4 to 2.12 (compiled > >> it last friday). > > >>>http://erlgtk.sourceforge.net/ > >> ? dead AFAIK. > > >> ? mats > >> _______________________________________________ > >> erlang-questions mailing list > >> erlang-questi... > >>http://www.erlang.org/mailman/listinfo/erlang-questions > > > _______________________________________________ > > erlang-questions mailing list > > erlang-questi... > >http://www.erlang.org/mailman/listinfo/erlang-questions > > _______________________________________________ > erlang-questions mailing list > erlang-questi...://www.erlang.org/mailman/listinfo/erlang-questions From ok Thu Oct 2 07:23:09 2008 From: ok (Richard O'Keefe) Date: Thu, 2 Oct 2008 18:23:09 +1300 Subject: [erlang-questions] The Erlang Rationale In-Reply-To: <6c2563b20810010649xdb362dcyefc9e361608b33f7@mail.gmail.com> References: <3dbc6d1c0809291502m3ad2147djfdc652a8e5c7a157@mail.gmail.com> <48E1F395.5040501@gmail.com> <3dbc6d1c0809300519kd46dbadsdfb670f71865b5@mail.gmail.com> <48E21D43.1040509@gmail.com> <4ac8254d0809300609m7c72c6b2je9774a70c629acf8@mail.gmail.com> <3dbc6d1c0809300630q35221794jf0922f370de6dd04@mail.gmail.com> <6c2563b20810010649xdb362dcyefc9e361608b33f7@mail.gmail.com> Message-ID: On 2 Oct 2008, at 2:49 am, Edwin Fine wrote: > This is a dissenting vote regarding macros. > > Macros *can* make maintenance harder, You've just agreed; this is not dissent. > just like gotos *can* create spaghetti code. Neither of them are > intrinsically bad, merely easy to misuse. Maintenance of large amounts of code has to be done with tools. Macros make it harder to produce accurate tools. The only freely available program I've come across that does a decent job of cross-referencing for *both* macros *and* the underlying symbols for C is CScout. (It isn't an Open Source program, but it is available in executable form for no money.) As far as I know there is no real equivalent for Erlang. > Used with care and discipline, they both arguably have a place in > good programming practice. As a matter of fact, I still use M4 on Java code. (Remember, Java 1.5 generics do *not* accept primitive types as arguments. If you want to do that without the very heavy overhead of Java boxing and unboxing, M4 is the only game in town.) > Now I may get shot down in flames for saying this, but tail > recursion in Erlang is effectively a restricted form of goto, Perfectly true. There's even a famous paper "Lambda, the Ultimate Goto". > and it's used a lot (not by choice over some other construct, though > - the language design forces the usage). > > There are some things that macros can do that I have not found as > easy (or possible) to do some other way, for example: > > -define(LOG_DBG(Msg, ArgList), iutil_log:log_debug(?MODULE, ?LINE, > Msg, ArgList)). > > Example usage: > > ?LOG_DBG("Received ~p from ~p~n", [Msg, Socket]). This is a rather interesting one. What could replace it? -module(flog). -export([flog/2]). flog(Format, Arguments) -> {Module, Line, _} = erlang:call_site(), iutil_log:log_debug(Module, Line, Format, Arguments). Some kind of primitive that extracted a return address and consulted a line number table. That could do it. In fact it could provide more information, such as {Function,Arity}. As a debugging tool, presumably it would not need to be fast. > > iutil_log:log_debug(?MODULE, ?LINE, "Received ~p from ~p~n", [Msg, > Socket]). But what if, instead of or in addition to ?MODULE and ?LINE, the system provided you with ?HERE, expanding to {Module, Line, {Function, Arity}}. Then iutil_log:flog(?HERE, "Received ~p from ~p~n", [Msg,Socket]) doesn't seem _that_ horrible. > > > If I find that debug logging is causing too much overhead, I can > decide to conditionally compile it: > > -ifdef(DEBUG). > -define(LOG_DBG(Msg, ArgList), iutil_log:log_debug(?MODULE, ? > LINE, Msg, ArgList)). > -else. > -define(LOG_DBG(Msg, ArgList), ok). > -endif. Suppose we had top-level variables instead. So Debug = false. -inline([flog/3]). flog({Module,Line,_}, Format, Arguments) when Debug -> iutil:log_debug(Module, Line, Format, Arguments); flog(_, _, _) -> ok. Now we are down to ... flog(?HERE, "Received ~p from ~p~n", [Msg,Socket]) ... with the *same* efficiency as the macro, as easily enabled or disabled, and no preprocessor. The only thing we need that we don't have now (for we do have inlining) is ?HERE, which is no harder to provide than ?LINE. I've been experimentally rewriting some Erlang modules to see what top level variables would look like. Rather nice, in fact. Well, we don't have those now, and we'd need non-trivial compiler changes to get them. So let's do without. -inline([debug/0, flog/3]). debug() -> false. flog(Where, Format, Arguments) -> case debug() of true -> {Module,Line,_} = Where, iutil:log_debug(Module, Line, Format, Arguments) ; false -> ok end. These functions we can write today. > > A minor inconvenience of the above is that if it uses variables that > are not otherwise used, you can get compile warnings when debug > logging is disabled. This is easily fixed by using the underscore: > _Unused. And the version using an inlined function doesn't have the problem in the first place. > If I don't like having to recompile the code to enable and disable > debug logging, but want to turn it on and off at run-time (and still > have negligible overhead when debug logging is disabled), I can do > this (and the source code using this does not change in any way, but > of course must undergo a once-off recompilation): > > -define( > LOG_DBG(Msg, ArgList), > case iutil_log:ok_to_log(debug) of > true -> > iutil_log:log_debug(?MODULE, ?LINE, Msg, ArgList); > false -> > ok > end > ). Ah, the old don't-evaluate-the-arguments trick. I've run into code that only worked when you had assertions enabled, because it relied on the argument of assert() being evaluated... > > Checking if the Msg and ArgList should be evaluated before calling > saves, at the cost of an efficient function call, potentially > enormous amounts of unnecessary list creation and destruction (and > garbage collection), not to mention any evaluation of the list > elements that might be needed. True. It also means that the debugging version and the non-debugging version of your program do not do the same thing. If the expressions involve only constants, variables, control structures, and calls to known pure functions, I would hope that -inline([flog/3]). flog(Where, Format, Arguments) when Debug -> case iutil_log:ok_to_log(debug) of true -> {Module, Line, _} = Where, iutil:log_debug(Module, Line, Format, Arguments) ; false -> ok end; flog(_, _, _) -> ok. ... flog(?HERE, "......", [.....]) ... would push the evaluation of the format and arguments into the one case branch that uses them. If it doesn't, we have far worse performance issues to worry about than this one. If the expressions involve side effects and calls to possibly impure functions, then you had better make sure they are _always_ evaluated, otherwise what you log won't be what happens when you are not logging. In this context, I find BitC's distinction between pure and impure functions _in the type system_ interesting. > > > In this case I would argue that the macro makes the code *more* > maintainable and easier to read, while keeping it efficient. Agreed, > if the macro changes (and this class of macro seldom changes) I will > need to recompile the dependent code, and this is definitely not > good, but as Lord Farquhar said, "[Many of you may be killed, but] > it is a sacrifice I am willing to make." ;-) The problem is that ?LOG_DBG could do *anything*, and it isn't as easy as it should be to find the definition. (I was going to explain what etags does with macros, since etags on my box claims to support Erlang, but what cd stdlib/src; etags -o fred *.erl does is to crash in strncpy(). Since it fails to note the arity of functions, it's dubiously useful anyway.) > The curious thing is that people keep on trotting out the *same* example of why the preprocessor is useful. We *have* inlining. If only we had ?HERE, then LOG_DBG("Received ~p from ~p~n", [Msg,Socket]) would be flog(?HERE, "Received ~p from ~p~n", [Msg,Socket]) which I for one don't regard as unduly burdensome. In fact the visible presence of ?HERE as an argument tells me that the location is being passed on, which is not so obvious in LOG_DBG. Actually, if we had ?HERE, things could get even better. If the compiler handled constant terms specially (using a single static copy instead of building a new copy on the heap), passing ?HERE could be as cheap as passing 42, and we could pass around one possibly detailed location term instead of separate module/line arguments. This would be nice to do for format strings too. From erlang-questions_efine Thu Oct 2 08:55:02 2008 From: erlang-questions_efine (Edwin Fine) Date: Thu, 2 Oct 2008 02:55:02 -0400 Subject: [erlang-questions] The Erlang Rationale In-Reply-To: References: <3dbc6d1c0809291502m3ad2147djfdc652a8e5c7a157@mail.gmail.com> <48E1F395.5040501@gmail.com> <3dbc6d1c0809300519kd46dbadsdfb670f71865b5@mail.gmail.com> <48E21D43.1040509@gmail.com> <4ac8254d0809300609m7c72c6b2je9774a70c629acf8@mail.gmail.com> <3dbc6d1c0809300630q35221794jf0922f370de6dd04@mail.gmail.com> <6c2563b20810010649xdb362dcyefc9e361608b33f7@mail.gmail.com> Message-ID: <6c2563b20810012355t5ea248a0q24deddcd415a85fe@mail.gmail.com> On Thu, Oct 2, 2008 at 1:23 AM, Richard O'Keefe wrote: > > On 2 Oct 2008, at 2:49 am, Edwin Fine wrote: > > This is a dissenting vote regarding macros. >> >> Macros *can* make maintenance harder, >> > > You've just agreed; this is not dissent. > Sorry, but I did not agree. You just read it that way. What I perhaps should have written is that you bluntly asserted that macros make maintenance harder. I am bluntly asserting that it is not necessarily so. That's dissent. Or maybe partial dissent, but there's dissent in there somewhere, I'm sure :) > > just like gotos *can* create spaghetti code. Neither of them are >> intrinsically bad, merely easy to misuse. >> > > Maintenance of large amounts of code has to be done with > tools. Macros make it harder to produce accurate tools. > The only freely available program I've come across that > does a decent job of cross-referencing for *both* macros > *and* the underlying symbols for C is CScout. (It isn't > an Open Source program, but it is available in executable > form for no money.) As far as I know there is no real > equivalent for Erlang. > I don't think this is a particularly compelling argument. I've been involved in maintenance of multi-million line systems and had much bigger fish to fry than macro-related difficulties with cross-reference tools. Maybe your experience has been different. > > > Used with care and discipline, they both arguably have a place in good >> programming practice. >> > > As a matter of fact, I still use M4 on Java code. > (Remember, Java 1.5 generics do *not* accept primitive types > as arguments. If you want to do that without the very heavy > overhead of Java boxing and unboxing, M4 is the only game in town.) > So macros are NOT that evil :) > > > Now I may get shot down in flames for saying this, but tail recursion in >> Erlang is effectively a restricted form of goto, >> > > Perfectly true. There's even a famous paper > "Lambda, the Ultimate Goto". > So the evil GOTO is not always evil, only sometimes. So it is for macros, or any dirty trick we have to pull because we never thought of the right way to do it originally and now we have to retrofit a bolt-on solution. > > > and it's used a lot (not by choice over some other construct, though - the >> language design forces the usage). >> >> There are some things that macros can do that I have not found as easy (or >> possible) to do some other way, for example: >> >> -define(LOG_DBG(Msg, ArgList), iutil_log:log_debug(?MODULE, ?LINE, Msg, >> ArgList)). >> >> Example usage: >> >> ?LOG_DBG("Received ~p from ~p~n", [Msg, Socket]). >> > > This is a rather interesting one. > What could replace it? > > -module(flog). > -export([flog/2]). > > flog(Format, Arguments) -> > {Module, Line, _} = erlang:call_site(), > iutil_log:log_debug(Module, Line, Format, Arguments). > > Some kind of primitive that extracted a return address and > consulted a line number table. That could do it. In fact it > could provide more information, such as {Function,Arity}. As > a debugging tool, presumably it would not need to be fast. > But it's not available *today*, and I need something that works *today* to give my customer. > > >> > iutil_log:log_debug(?MODULE, ?LINE, "Received ~p from ~p~n", [Msg, >> Socket]). >> > > But what if, instead of or in addition to ?MODULE and ?LINE, > the system provided you with ?HERE, expanding to > {Module, Line, {Function, Arity}}. Then > > iutil_log:flog(?HERE, "Received ~p from ~p~n", [Msg,Socket]) > > doesn't seem _that_ horrible. > Sorry to belabor the point, but what if it did? It doesn't. What if we all lived in peace and harmony and respected each other's rights? > > >> >> If I find that debug logging is causing too much overhead, I can decide to >> conditionally compile it: >> >> -ifdef(DEBUG). >> -define(LOG_DBG(Msg, ArgList), iutil_log:log_debug(?MODULE, ?LINE, Msg, >> ArgList)). >> -else. >> -define(LOG_DBG(Msg, ArgList), ok). >> -endif. >> > > Suppose we had top-level variables instead. So > But we don't. I wish we did. > > Debug = false. > > -inline([flog/3]). > > flog({Module,Line,_}, Format, Arguments) when Debug -> > iutil:log_debug(Module, Line, Format, Arguments); > flog(_, _, _) -> > ok. > > Now we are down to > > ... flog(?HERE, "Received ~p from ~p~n", [Msg,Socket]) ... > > with the *same* efficiency as the macro, as easily enabled or > disabled, and no preprocessor. The only thing we need that we > don't have now (for we do have inlining) is ?HERE, which is no > harder to provide than ?LINE. > > I've been experimentally rewriting some Erlang modules to see > what top level variables would look like. Rather nice, in fact. > Well, we don't have those now, and we'd need non-trivial compiler > changes to get them. So let's do without. Exactly my point. > > > -inline([debug/0, flog/3]). > > debug() -> false. > > flog(Where, Format, Arguments) -> > case debug() > of true -> > {Module,Line,_} = Where, > iutil:log_debug(Module, Line, Format, Arguments) > ; false -> > ok > end. > > These functions we can write today. > True - but I was working towards my ultimate point that having to recompile is a pain and wanted the ability to change run-time log levels. And, using the above code, won't you get copious compiler or Dialyzer warnings complaining that only one branch of the case will ever be reached? How would you suppress those? Or are you going to invent a suitable -pragma() for Erlang :) ? > > >> > A minor inconvenience of the above is that if it uses variables that are >> not otherwise used, you can get compile warnings when debug logging is >> disabled. This is easily fixed by using the underscore: _Unused. >> > > And the version using an inlined function doesn't have the problem > in the first place. > True. Does the inlined function stay inlined even if you compile with [debug_info]? I truly don't know - in C++ this often disables inlining. > > > If I don't like having to recompile the code to enable and disable debug >> logging, but want to turn it on and off at run-time (and still have >> negligible overhead when debug logging is disabled), I can do this (and the >> source code using this does not change in any way, but of course must >> undergo a once-off recompilation): >> >> -define( >> LOG_DBG(Msg, ArgList), >> case iutil_log:ok_to_log(debug) of >> true -> >> iutil_log:log_debug(?MODULE, ?LINE, Msg, ArgList); >> false -> >> ok >> end >> ). >> > > Ah, the old don't-evaluate-the-arguments trick. > I've run into code that only worked when you had > assertions enabled, because it relied on the > argument of assert() being evaluated... > Ah, the old I've-seen-crap-code trick. Yes, absolutely true, and anyone worth their salt will never put important code into log statements that won't get evaluated. > >> > Checking if the Msg and ArgList should be evaluated before calling saves, >> at the cost of an efficient function call, potentially enormous amounts of >> unnecessary list creation and destruction (and garbage collection), not to >> mention any evaluation of the list elements that might be needed. >> > > True. It also means that the debugging version and the non-debugging > version of your program do not do the same thing. > Only if I'm careless. Anyway, the whole point of having a debugging and non-debugging version is that they DON'T do the same thing - otherwise why have two versions? But I am splitting hairs here - I know you mean that from a functional standpoint, they won't do the same unless you take care. But that's true of anything to do with programming. > If the expressions involve only constants, variables, control > structures, and calls to known pure functions, I would hope that > And they absolutely should! > > -inline([flog/3]). > flog(Where, Format, Arguments) when Debug -> %%% Huh?? > > case iutil_log:ok_to_log(debug) > of true -> > {Module, Line, _} = Where, > iutil:log_debug(Module, Line, Format, Arguments) > ; false -> > ok > end; > flog(_, _, _) -> > ok. > > ... flog(?HERE, "......", [.....]) ... > > would push the evaluation of the format and arguments into the one > case branch that uses them. If it doesn't, we have far worse > performance issues to worry about than this one. > Where does Debug come from? Is it a (non-existent) top-level variable? > If the expressions involve side effects and calls to possibly > impure functions, then you had better make sure they are _always_ > evaluated, otherwise what you log won't be what happens when you > are not logging. Totally agreed. But that's true of any conditional code, not just that to do with logging. You have to be careful. I suppose that with a macro that you don't understand might not always execute, you run a higher risk of screwing up. Ah, if only languages would give us what we need without macros....! > > > In this context, I find BitC's distinction between pure and impure > functions _in the type system_ interesting. > That would be very useful - does that mean the compiler automatically flags functions as pure or impure based on their side-effects? > >> >> In this case I would argue that the macro makes the code *more* >> maintainable and easier to read, while keeping it efficient. Agreed, if the >> macro changes (and this class of macro seldom changes) I will need to >> recompile the dependent code, and this is definitely not good, but as Lord >> Farquhar said, "[Many of you may be killed, but] it is a sacrifice I am >> willing to make." ;-) >> > > The problem is that ?LOG_DBG could do *anything*, > and it isn't as easy as it should be to find the definition. That's also its strength (to be able to do ANYTHING and you don't have to change the code). To find the definition using find and grep isn't *that* hard, is it? I have searched the entire Erlang source code base for things of interest in under a minute with find/grep. Maybe it's slow using that 500MHz UltraSparc you are saddled with :( > (I was going to explain what etags does with macros, since > etags on my box claims to support Erlang, but what > cd stdlib/src; etags -o fred *.erl > does is to crash in strncpy(). Since it fails to note the > arity of functions, it's dubiously useful anyway.) The authors probably weren't careful with the side-effects of their debug log statements :) > > >> The curious thing is that people keep on trotting out the *same* > example of why the preprocessor is useful. We *have* inlining. We keep trotting out the *same* example because there are no *existing* solutions that do what I want without using it!! > > If only we had ?HERE, But we don't. I have to work with the real world. If ?HERE was here I would use it! > then > > LOG_DBG("Received ~p from ~p~n", [Msg,Socket]) > > would be > > flog(?HERE, "Received ~p from ~p~n", [Msg,Socket]) > > which I for one don't regard as unduly burdensome. In > fact the visible presence of ?HERE as an argument tells > me that the location is being passed on, which is not so > obvious in LOG_DBG. > Maybe so, but it gives me the flexibility to remove the location being passed later if I find it is causing a problem, say with performance. > Actually, if we had ?HERE, things could get even better. > If the compiler handled constant terms specially (using a > single static copy instead of building a new copy on the > heap), passing ?HERE could be as cheap as passing 42, and > we could pass around one possibly detailed location term > instead of separate module/line arguments. This would be > nice to do for format strings too. > Well, I for one would vote for a compiler that detected constant terms and kept them statically!! The one important thing that I perhaps didn't understand from your discussion is how you proposed to change the logging level at run time, given the *existing* features of Erlang. Understand that I gave the LOG_DBG macro as an example. As it happens, I have LOG_TRACE, LOG_INFO, LOG_WARN, and LOG_ERROR as well. I know that Erlang has trace facilities, but they are not retrospective. I need to go back in the logs and see what happened historically. I don't like the idea of sending all logging operations to a central manager process that decides to throw away the ones it doesn't want, because I don't want the sending process to be spewing out useless messages and using up CPU and GC time, and the manager process to be throwing things away. I have found historical logs to be an invaluable part of the fault-finding process, so I pepper my code liberally with all kinds of log statements - and I want to do that with the least runtime cost for the most debugging benefit. Let me tell you what I have done, and this will probably give you nightmares because it's a terrible hack, but it works well. I hacked it like this because I didn't want to (a) pass log level variables in the parameter list of every single function I ever write (b) store the log level in the process dictionary where it has to be looked up thousands of times a second (c) even worse, store it in an ETS table. In the absence of top-level variables, I faked a top-level variable as follows. I wrote a module that exports only one function, log_level(). This function is hard-coded to return (say) the atom 'info', e.g. log_level() -> info. If I want to change the logging level to debug at runtime, I simply rewrite the one line of code (plus module and export statements) in a string and recompile the code at runtime, then purge. The logging level then changes and I get debug, warning, error and info logs. (And I do understand that the historical aspect I find so important can be affected by changing the logging level, but I ensure that I log the most critical information at all times). My understanding is that a call to mod:func is very cheap, probably more so than any process dictionary or ETS lookups. So this way, for the price of a bit of skulduggery, I get tremendous flexibility at a low runtime cost. I am sure that the gurus will find some horrible flaw in this scheme, which I'd like to hear about so I can fix it, but for now it is working very well indeed. I do look forward to the implementation an EEP for top-level variables, though, then I can throw this ugliness away. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081002/e58b3d07/attachment-0001.html From mikpe Thu Oct 2 09:57:35 2008 From: mikpe (Mikael Pettersson) Date: Thu, 2 Oct 2008 09:57:35 +0200 Subject: [erlang-questions] Building 64-bit Erlang on Solaris 11 In-Reply-To: <48E3D56A.4060807@alertlogic.net> References: <11584396-2118-469C-88DA-B234E10130CA@gmail.com> <48E3D56A.4060807@alertlogic.net> Message-ID: <18660.32495.820483.196948@harpo.it.uu.se> Paul Fisher writes: > Joel Reymont wrote: > > ./configure --prefix=/opt/local --enable-64bit CFLAGS='-m64' > > ... > > gmake > > ... > > ld: fatal: file obj/i386-pc-solaris2.11/opt/plain/erl_main.o: wrong > > ELF class: ELFCLASS64 > > ld: fatal: File processing errors. No output written to /home/admin/ > > otp_src_R12B-4/bin/i386-pc-solaris2.11/beam > > > > What am I doing wrong? > > > > Thanks, Joel > > > > P.S. Omitting CFLAGS='-m64' builds a 32-bit Erlang. > > Not so straight forward (esp. if you use linked in drivers as we do). > Here is what it takes I believe the problem is that the otp build system probably overrides CFLAGS, which would cancel any user setting of CFLAGS. What I and others typically do for 64-bit builds is to set CC='gcc -m64' or to point CC to a script that always adds -m64. The real fix IMO is not to add --enable-64bit because in theory there can be other compilation mode defaults the user may want to override. Instead the build system should be made to respect the user's CFLAGS. From lestat Thu Oct 2 10:22:55 2008 From: lestat (Tamas Nagy) Date: Thu, 2 Oct 2008 09:22:55 +0100 Subject: [erlang-questions] The Erlang Rationale In-Reply-To: <6c2563b20810012355t5ea248a0q24deddcd415a85fe@mail.gmail.com> References: <3dbc6d1c0809291502m3ad2147djfdc652a8e5c7a157@mail.gmail.com> <48E1F395.5040501@gmail.com> <3dbc6d1c0809300519kd46dbadsdfb670f71865b5@mail.gmail.com> <48E21D43.1040509@gmail.com> <4ac8254d0809300609m7c72c6b2je9774a70c629acf8@mail.gmail.com> <3dbc6d1c0809300630q35221794jf0922f370de6dd04@mail.gmail.com> <6c2563b20810010649xdb362dcyefc9e361608b33f7@mail.gmail.com> <6c2563b20810012355t5ea248a0q24deddcd415a85fe@mail.gmail.com> Message-ID: <4498055F-B928-4551-8A25-4281303664D1@elte.hu> Hi! If you have problems with macro support for cross referencing take a look at RefactorErl. Although it is a refactoring tool it provides a quite extensive API to call, macro and record cross referencing. I do not see any obstacle which would make it impossible for somebody - with a bit of spare time - to create a tool on top of the data provided by the system. Best of all it supports macros which cut into the syntactical structure of the code. For example: ... -define(ADD(X,Y), + X + Y). ... foo(X, Y) -> 3 ?ADD(X,Y). ... I'm sure you can come up with uglier but more meaningful examples as well. Regards, Tamas On 2 Oct 2008, at 07:55, Edwin Fine wrote: > > > On Thu, Oct 2, 2008 at 1:23 AM, Richard O'Keefe > wrote: > > On 2 Oct 2008, at 2:49 am, Edwin Fine wrote: > > This is a dissenting vote regarding macros. > > Macros *can* make maintenance harder, > > You've just agreed; this is not dissent. > > Sorry, but I did not agree. You just read it that way. What I > perhaps should have written is that you bluntly asserted that macros > make maintenance harder. I am bluntly asserting that it is not > necessarily so. That's dissent. Or maybe partial dissent, but > there's dissent in there somewhere, I'm sure :) > > > > just like gotos *can* create spaghetti code. Neither of them are > intrinsically bad, merely easy to misuse. > > Maintenance of large amounts of code has to be done with > tools. Macros make it harder to produce accurate tools. > The only freely available program I've come across that > does a decent job of cross-referencing for *both* macros > *and* the underlying symbols for C is CScout. (It isn't > an Open Source program, but it is available in executable > form for no money.) As far as I know there is no real > equivalent for Erlang. > > I don't think this is a particularly compelling argument. I've been > involved in maintenance of multi-million line systems and had much > bigger fish to fry than macro-related difficulties with cross- > reference tools. Maybe your experience has been different. > > > > Used with care and discipline, they both arguably have a place in > good programming practice. > > As a matter of fact, I still use M4 on Java code. > (Remember, Java 1.5 generics do *not* accept primitive types > as arguments. If you want to do that without the very heavy > overhead of Java boxing and unboxing, M4 is the only game in town.) > > So macros are NOT that evil :) > > > > Now I may get shot down in flames for saying this, but tail > recursion in Erlang is effectively a restricted form of goto, > > Perfectly true. There's even a famous paper > "Lambda, the Ultimate Goto". > > So the evil GOTO is not always evil, only sometimes. So it is for > macros, or any dirty trick we have to pull because we never thought > of the right way to do it originally and now we have to retrofit a > bolt-on solution. > > > > and it's used a lot (not by choice over some other construct, though > - the language design forces the usage). > > There are some things that macros can do that I have not found as > easy (or possible) to do some other way, for example: > > -define(LOG_DBG(Msg, ArgList), iutil_log:log_debug(?MODULE, ?LINE, > Msg, ArgList)). > > Example usage: > > ?LOG_DBG("Received ~p from ~p~n", [Msg, Socket]). > > This is a rather interesting one. > What could replace it? > > -module(flog). > -export([flog/2]). > > flog(Format, Arguments) -> > {Module, Line, _} = erlang:call_site(), > iutil_log:log_debug(Module, Line, Format, Arguments). > > Some kind of primitive that extracted a return address and > consulted a line number table. That could do it. In fact it > could provide more information, such as {Function,Arity}. As > a debugging tool, presumably it would not need to be fast. > > But it's not available *today*, and I need something that works > *today* to give my customer. > > > > > iutil_log:log_debug(?MODULE, ?LINE, "Received ~p from ~p~n", [Msg, > Socket]). > > But what if, instead of or in addition to ?MODULE and ?LINE, > the system provided you with ?HERE, expanding to > {Module, Line, {Function, Arity}}. Then > > iutil_log:flog(?HERE, "Received ~p from ~p~n", [Msg,Socket]) > > doesn't seem _that_ horrible. > > Sorry to belabor the point, but what if it did? It doesn't. What if > we all lived in peace and harmony and respected each other's rights? > > > > > If I find that debug logging is causing too much overhead, I can > decide to conditionally compile it: > > -ifdef(DEBUG). > -define(LOG_DBG(Msg, ArgList), iutil_log:log_debug(?MODULE, ? > LINE, Msg, ArgList)). > -else. > -define(LOG_DBG(Msg, ArgList), ok). > -endif. > > Suppose we had top-level variables instead. So > > But we don't. I wish we did. > > > Debug = false. > > -inline([flog/3]). > > flog({Module,Line,_}, Format, Arguments) when Debug -> > iutil:log_debug(Module, Line, Format, Arguments); > flog(_, _, _) -> > ok. > > Now we are down to > > ... flog(?HERE, "Received ~p from ~p~n", [Msg,Socket]) ... > > with the *same* efficiency as the macro, as easily enabled or > disabled, and no preprocessor. The only thing we need that we > don't have now (for we do have inlining) is ?HERE, which is no > harder to provide than ?LINE. > > I've been experimentally rewriting some Erlang modules to see > what top level variables would look like. Rather nice, in fact. > Well, we don't have those now, and we'd need non-trivial compiler > changes to get them. So let's do without. > > Exactly my point. > > > > -inline([debug/0, flog/3]). > > debug() -> false. > > flog(Where, Format, Arguments) -> > case debug() > of true -> > {Module,Line,_} = Where, > iutil:log_debug(Module, Line, Format, Arguments) > ; false -> > ok > end. > > These functions we can write today. > > True - but I was working towards my ultimate point that having to > recompile is a pain and wanted the ability to change run-time log > levels. And, using the above code, won't you get copious compiler or > Dialyzer warnings complaining that only one branch of the case will > ever be reached? How would you suppress those? Or are you going to > invent a suitable -pragma() for Erlang :) ? > > > > > > A minor inconvenience of the above is that if it uses variables that > are not otherwise used, you can get compile warnings when debug > logging is disabled. This is easily fixed by using the underscore: > _Unused. > > And the version using an inlined function doesn't have the problem > in the first place. > > True. Does the inlined function stay inlined even if you compile > with [debug_info]? I truly don't know - in C++ this often disables > inlining. > > > > If I don't like having to recompile the code to enable and disable > debug logging, but want to turn it on and off at run-time (and still > have negligible overhead when debug logging is disabled), I can do > this (and the source code using this does not change in any way, but > of course must undergo a once-off recompilation): > > -define( > LOG_DBG(Msg, ArgList), > case iutil_log:ok_to_log(debug) of > true -> > iutil_log:log_debug(?MODULE, ?LINE, Msg, ArgList); > false -> > ok > end > ). > > Ah, the old don't-evaluate-the-arguments trick. > I've run into code that only worked when you had > assertions enabled, because it relied on the > argument of assert() being evaluated... > > Ah, the old I've-seen-crap-code trick. Yes, absolutely true, and > anyone worth their salt will never put important code into log > statements that won't get evaluated. > > > > > Checking if the Msg and ArgList should be evaluated before calling > saves, at the cost of an efficient function call, potentially > enormous amounts of unnecessary list creation and destruction (and > garbage collection), not to mention any evaluation of the list > elements that might be needed. > > True. It also means that the debugging version and the non-debugging > version of your program do not do the same thing. > > Only if I'm careless. Anyway, the whole point of having a debugging > and non-debugging version is that they DON'T do the same thing - > otherwise why have two versions? But I am splitting hairs here - I > know you mean that from a functional standpoint, they won't do the > same unless you take care. But that's true of anything to do with > programming. > > > If the expressions involve only constants, variables, control > structures, and calls to known pure functions, I would hope that > > And they absolutely should! > > > -inline([flog/3]). > flog(Where, Format, Arguments) when Debug -> %%% Huh?? > > case iutil_log:ok_to_log(debug) > of true -> > {Module, Line, _} = Where, > iutil:log_debug(Module, Line, Format, Arguments) > ; false -> > ok > end; > flog(_, _, _) -> > ok. > > ... flog(?HERE, "......", [.....]) ... > > would push the evaluation of the format and arguments into the one > case branch that uses them. If it doesn't, we have far worse > performance issues to worry about than this one. > > Where does Debug come from? Is it a (non-existent) top-level variable? > > > If the expressions involve side effects and calls to possibly > impure functions, then you had better make sure they are _always_ > evaluated, otherwise what you log won't be what happens when you > are not logging. > > Totally agreed. But that's true of any conditional code, not just > that to do with logging. You have to be careful. I suppose that with > a macro that you don't understand might not always execute, you run > a higher risk of screwing up. Ah, if only languages would give us > what we need without macros....! > > > > In this context, I find BitC's distinction between pure and impure > functions _in the type system_ interesting. > > That would be very useful - does that mean the compiler > automatically flags functions as pure or impure based on their side- > effects? > > > > > In this case I would argue that the macro makes the code *more* > maintainable and easier to read, while keeping it efficient. Agreed, > if the macro changes (and this class of macro seldom changes) I will > need to recompile the dependent code, and this is definitely not > good, but as Lord Farquhar said, "[Many of you may be killed, but] > it is a sacrifice I am willing to make." ;-) > > The problem is that ?LOG_DBG could do *anything*, > and it isn't as easy as it should be to find the definition. > > That's also its strength (to be able to do ANYTHING and you don't > have to change the code). To find the definition using find and grep > isn't *that* hard, is it? I have searched the entire Erlang source > code base for things of interest in under a minute with find/grep. > Maybe it's slow using that 500MHz UltraSparc you are saddled with :( > > > (I was going to explain what etags does with macros, since > etags on my box claims to support Erlang, but what > cd stdlib/src; etags -o fred *.erl > does is to crash in strncpy(). Since it fails to note the > arity of functions, it's dubiously useful anyway.) > > The authors probably weren't careful with the side-effects of their > debug log statements :) > > > > > The curious thing is that people keep on trotting out the *same* > example of why the preprocessor is useful. We *have* inlining. > > We keep trotting out the *same* example because there are no > *existing* solutions that do what I want without using it!! > > > If only we had ?HERE, > > But we don't. I have to work with the real world. If ?HERE was here > I would use it! > > then > > > LOG_DBG("Received ~p from ~p~n", [Msg,Socket]) > > would be > > flog(?HERE, "Received ~p from ~p~n", [Msg,Socket]) > > which I for one don't regard as unduly burdensome. In > fact the visible presence of ?HERE as an argument tells > me that the location is being passed on, which is not so > obvious in LOG_DBG. > > Maybe so, but it gives me the flexibility to remove the location > being passed later if I find it is causing a problem, say with > performance. > > > Actually, if we had ?HERE, things could get even better. > If the compiler handled constant terms specially (using a > single static copy instead of building a new copy on the > heap), passing ?HERE could be as cheap as passing 42, and > we could pass around one possibly detailed location term > instead of separate module/line arguments. This would be > nice to do for format strings too. > > Well, I for one would vote for a compiler that detected constant > terms and kept them statically!! > > The one important thing that I perhaps didn't understand from your > discussion is how you proposed to change the logging level at run > time, given the *existing* features of Erlang. > > Understand that I gave the LOG_DBG macro as an example. As it > happens, I have LOG_TRACE, LOG_INFO, LOG_WARN, and LOG_ERROR as > well. I know that Erlang has trace facilities, but they are not > retrospective. I need to go back in the logs and see what happened > historically. I don't like the idea of sending all logging > operations to a central manager process that decides to throw away > the ones it doesn't want, because I don't want the sending process > to be spewing out useless messages and using up CPU and GC time, and > the manager process to be throwing things away. I have found > historical logs to be an invaluable part of the fault-finding > process, so I pepper my code liberally with all kinds of log > statements - and I want to do that with the least runtime cost for > the most debugging benefit. > > Let me tell you what I have done, and this will probably give you > nightmares because it's a terrible hack, but it works well. I hacked > it like this because I didn't want to (a) pass log level variables > in the parameter list of every single function I ever write (b) > store the log level in the process dictionary where it has to be > looked up thousands of times a second (c) even worse, store it in an > ETS table. In the absence of top-level variables, I faked a top- > level variable as follows. > > I wrote a module that exports only one function, log_level(). This > function is hard-coded to return (say) the atom 'info', e.g. > > log_level() -> info. > > If I want to change the logging level to debug at runtime, I simply > rewrite the one line of code (plus module and export statements) in > a string and recompile the code at runtime, then purge. The logging > level then changes and I get debug, warning, error and info logs. > (And I do understand that the historical aspect I find so important > can be affected by changing the logging level, but I ensure that I > log the most critical information at all times). My understanding is > that a call to mod:func is very cheap, probably more so than any > process dictionary or ETS lookups. So this way, for the price of a > bit of skulduggery, I get tremendous flexibility at a low runtime > cost. I am sure that the gurus will find some horrible flaw in this > scheme, which I'd like to hear about so I can fix it, but for now it > is working very well indeed. > > I do look forward to the implementation an EEP for top-level > variables, though, then I can throw this ugliness away. > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081002/1ced791b/attachment-0001.html From joelr1 Thu Oct 2 11:03:40 2008 From: joelr1 (Joel Reymont) Date: Thu, 2 Oct 2008 10:03:40 +0100 Subject: [erlang-questions] Building 64-bit Erlang on Solaris 11 In-Reply-To: <18660.32495.820483.196948@harpo.it.uu.se> References: <11584396-2118-469C-88DA-B234E10130CA@gmail.com> <48E3D56A.4060807@alertlogic.net> <18660.32495.820483.196948@harpo.it.uu.se> Message-ID: <80083D46-CA96-4A7F-BE04-CCDCA092D328@gmail.com> On Oct 2, 2008, at 8:57 AM, Mikael Pettersson wrote: > I believe the problem is that the otp build system probably > overrides CFLAGS, which would cancel any user setting of CFLAGS. > What I and others typically do for 64-bit builds is to set > CC='gcc -m64' or to point CC to a script that always adds -m64. That doesn't work too well... checking for a compiler that handles jumptables... /home/admin/ otp_src_R12B-4/erts/configure: line 20569: test: too many arguments /home/admin/otp_src_R12B-4/erts/configure: line 20587: test: too many arguments gcc -m64 /home/admin/otp_src_R12B-4/erts/configure: line 20660: test: too many arguments checking for static ZLib to be used by SSL in standard locations... no -- wagerlabs.com From mikpe Thu Oct 2 12:16:56 2008 From: mikpe (Mikael Pettersson) Date: Thu, 2 Oct 2008 12:16:56 +0200 Subject: [erlang-questions] Building 64-bit Erlang on Solaris 11 In-Reply-To: <80083D46-CA96-4A7F-BE04-CCDCA092D328@gmail.com> References: <11584396-2118-469C-88DA-B234E10130CA@gmail.com> <48E3D56A.4060807@alertlogic.net> <18660.32495.820483.196948@harpo.it.uu.se> <80083D46-CA96-4A7F-BE04-CCDCA092D328@gmail.com> Message-ID: <18660.40856.836062.671229@harpo.it.uu.se> Joel Reymont writes: > > On Oct 2, 2008, at 8:57 AM, Mikael Pettersson wrote: > > > I believe the problem is that the otp build system probably > > overrides CFLAGS, which would cancel any user setting of CFLAGS. > > What I and others typically do for 64-bit builds is to set > > CC='gcc -m64' or to point CC to a script that always adds -m64. > > > That doesn't work too well... > > checking for a compiler that handles jumptables... /home/admin/ > otp_src_R12B-4/erts/configure: line 20569: test: too many arguments > /home/admin/otp_src_R12B-4/erts/configure: line 20587: test: too many > arguments > gcc -m64 > /home/admin/otp_src_R12B-4/erts/configure: line 20660: test: too many > arguments > checking for static ZLib to be used by SSL in standard locations... no Maybe I misremembered the CC='gcc -m64' ./configure approach, it does work in other projects. The auxiliary script approach is known to work in Erlang however: cat > /tmp/gcc64 #!/bin/sh exec gcc -m64 "$@" ^D chmod +x /tmp/gcc64 CC=/tmp/gcc64 ./configure make From bgustavsson Thu Oct 2 12:31:03 2008 From: bgustavsson (Bjorn Gustavsson) Date: Thu, 2 Oct 2008 12:31:03 +0200 Subject: [erlang-questions] The Erlang Rationale In-Reply-To: References: <3dbc6d1c0809291502m3ad2147djfdc652a8e5c7a157@mail.gmail.com> <48E1F395.5040501@gmail.com> <3dbc6d1c0809300519kd46dbadsdfb670f71865b5@mail.gmail.com> <48E21D43.1040509@gmail.com> <4ac8254d0809300609m7c72c6b2je9774a70c629acf8@mail.gmail.com> <3dbc6d1c0809300630q35221794jf0922f370de6dd04@mail.gmail.com> <6c2563b20810010649xdb362dcyefc9e361608b33f7@mail.gmail.com> Message-ID: <6672d0160810020331h1fa3f6b5x95da792849b554fe@mail.gmail.com> On Thu, Oct 2, 2008 at 7:23 AM, Richard O'Keefe wrote: > > Actually, if we had ?HERE, things could get even better. > If the compiler handled constant terms specially (using a > single static copy instead of building a new copy on the > heap), passing ?HERE could be as cheap as passing 42, and > we could pass around one possibly detailed location term > instead of separate module/line arguments. This would be > nice to do for format strings too. > > The compiler (and run-time system) in R12B actually already does that. That was one of the highlights of the R12B release. /Bjorn -- Bj?rn Gustavsson, Erlang/OTP, Ericsson AB -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081002/224d6d73/attachment.html From vychodil.hynek Thu Oct 2 13:05:48 2008 From: vychodil.hynek (Hynek Vychodil) Date: Thu, 2 Oct 2008 13:05:48 +0200 Subject: [erlang-questions] Erlang doesn't suck In-Reply-To: <48E3E4FF.3020403@cs.ntua.gr> References: <48E3A1E6.4090307@alertlogic.net> <9D9606A2-0064-471E-B214-9E82DC850982@gmail.com> <48E3A86A.8010508@alertlogic.net> <28B99EDD-C840-4E3F-B59C-77A89F371B12@gmail.com> <48E3E4FF.3020403@cs.ntua.gr> Message-ID: <20081002110548.66AFB24064@relay.gooddata.com> I would like notice that hipe can cause performance lost for some special cases. There is not simple equation, switch on hipe and you gain some amount of performance surplus. Especially when you have tight loop over not so much complex data structures you can gain big amount of performance. When you do big amount of inter module calls you gain less and when you do big amount of message passings you can lost some performance when switch it on. On Wed, Oct 1, 2008 at 11:00 PM, Kostis Sagonas wrote: > Joel Reymont wrote: > > On Oct 1, 2008, at 5:42 PM, Paul Fisher wrote: > > > > There's certainly an increase in throughput (request per second) with > > hipe, even under 32 bits. > > > > Is there a way to mass-hipe-compile all of OTP? > > Not an easy one that I know of. We have discussed many times with the > OTP folks the possibility to add such a configure option, but so far it > has not happened. Yet another item for the upcoming meeting with them. > > Perhaps this option will be available in R12B-5. > > Kostis > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -- --Hynek (Pichi) Vychodil -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081002/d62fa80b/attachment.html From saleyn Thu Oct 2 13:32:24 2008 From: saleyn (Serge Aleynikov) Date: Thu, 02 Oct 2008 07:32:24 -0400 Subject: [erlang-questions] GTK bindings In-Reply-To: <68918cba-a4cd-45bd-a47b-50684819ca16@m45g2000hsb.googlegroups.com> References: <48CF2F1B.3070003@lionet.info> <2ae3549f-f1cb-4e3c-b7e3-d805c6de372a@m36g2000hse.googlegroups.com> <48CFF05B.90401@lionet.info> <15b6a55b-956f-45c8-b412-76751fe630ab@e53g2000hsa.googlegroups.com> <087d239c-07b5-47ef-9372-ae097ca12bcd@m45g2000hsb.googlegroups.com> <3dbc6d1c0809161457v2ed4f29bxe16bcc124dbf06f5@mail.gmail.com> <14f0e3620809161547x32377a37ke4c9abee0a8c41e1@mail.gmail.com> <3dbc6d1c0809161643t33fb3a80l7cb4b330333a1ef7@mail.gmail.com> <4ac8254d0809170244s4ebd31b1y4d0b361cdf3cb76f@mail.gmail.com> <48D1FC87.8030601@it.uu.se> <48E0C70D.5020700@gmail.com> <48E3AD6F.5050909@gmail.com> <48E3B568.2010702@gmail.com> <68918cba-a4cd-45bd-a47b-50684819ca16@m45g2000hsb.googlegroups.com> Message-ID: <48E4B148.4060901@gmail.com> Actually it turned out that the server I was running it on had several versions of pango, cairo, gtk+, x11, xml and other dependencies, so I had to play with settings to enforce selection of alternative libraries until I got it to work. YourSurrogateGod wrote: > Could you please show your Makefile? > > On Oct 1, 1:37 pm, Serge Aleynikov wrote: >> Actually I poked around with the makefile settings for gtknode and >> somehow the problem went away... >> >> >> >> >> From devdoer2 Thu Oct 2 13:32:58 2008 From: devdoer2 (devdoer bird) Date: Thu, 2 Oct 2008 19:32:58 +0800 Subject: [erlang-questions] cean:install can't install iconv Message-ID: HI: I run cean:install(iconv) and got the msg "error: iconv not found in download". Is cean available for R12B now? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081002/e2f6fc75/attachment.html From psa Thu Oct 2 13:52:05 2008 From: psa (=?ISO-8859-1?Q?Paulo_S=E9rgio_Almeida?=) Date: Thu, 02 Oct 2008 12:52:05 +0100 Subject: [erlang-questions] Documentation: type of filename parameter in ets:tab2file/2 In-Reply-To: <20081002110548.66AFB24064@relay.gooddata.com> References: <48E3A1E6.409030 7@alertlogic.net><9D9606A2-0064-471E-B214-9E82DC850982@gmail.com><48E3A86A. 8010508@alertlogic.net><28B99EDD-C840-4E3F-B59C-77A89F371B12@gmail.com><48E 3E4FF.3020403@cs.ntua.gr> <20081002110548.66AFB24064@relay.gooddata.com> Message-ID: <48E4B5E5.1040204@di.uminho.pt> Hi all, I noticed that the documentation of ets:tab2file/2 says: tab2file(Tab, Filename) -> ok | {error,Reason} Filename = string() | atom() Shouldn't it be a name() instead as in the file module: name() = string() | atom() | DeepList DeepList = [char() | atom() | DeepList] I tried using a deeplist and it works (as it should if it uses the file module). Regards, Paulo From eliliang Thu Oct 2 13:48:32 2008 From: eliliang (Eli Liang) Date: Thu, 2 Oct 2008 04:48:32 -0700 (PDT) Subject: [erlang-questions] Is it possible to build an 64-bit Erlang for Windows? Message-ID: <433485.46774.qm@web30402.mail.mud.yahoo.com> I've looked through the README.win32 file in the source, and it is leading me to believe that it would be difficult to build an x64 flavor of the binaries for Windows Vista x64. Has anyone tried this? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081002/39d58f15/attachment.html From mikpe Thu Oct 2 15:27:47 2008 From: mikpe (Mikael Pettersson) Date: Thu, 2 Oct 2008 15:27:47 +0200 Subject: [erlang-questions] Building 64-bit Erlang on Solaris 11 In-Reply-To: <6E6D4A6C-542D-46BC-85B9-5F52E4C37D3A@alertlogic.com> References: <11584396-2118-469C-88DA-B234E10130CA@gmail.com> <48E3D56A.4060807@alertlogic.net> <18660.32495.820483.196948@harpo.it.uu.se> <80083D46-CA96-4A7F-BE04-CCDCA092D328@gmail.com> <18660.40856.836062.671229@harpo.it.uu.se> <6E6D4A6C-542D-46BC-85B9-5F52E4C37D3A@alertlogic.com> Message-ID: <18660.52307.581140.533@harpo.it.uu.se> Paul Fisher writes: > The problem that I ran into was the fact that LD needs to be > overridden similarly. In addition, DED_xxxx would still still end up > wrong. Finally there a few things that still needed to be fixed up by > hand. > > I did the "enable-64bit" patch because the build already handled Mac > OSX that way. I just cleaned it and generalized the existing approach. > > Can whomever maintains the build cruft on the OTP team comment on > directio? Post a bug report to erlang-bugs, that's what it's there for. From kostis Thu Oct 2 16:21:39 2008 From: kostis (Kostis Sagonas) Date: Thu, 02 Oct 2008 17:21:39 +0300 Subject: [erlang-questions] Documentation: type of filename parameter in ets:tab2file/2 In-Reply-To: <48E4B5E5.1040204@di.uminho.pt> References: <48E3A1E6.409030 7@alertlogic.net><9D9606A2-0064-471E-B214-9E82DC850982@gmail.com><48E3A86A. 8010508@alertlogic.net><28B99EDD-C840-4E3F-B59C-77A89F371B12@gmail.com><48E 3E4FF.3020403@cs.ntua.gr> <20081002110548.66AFB24064@relay.gooddata.com> <48E4B5E5.1040204@di.uminho.pt> Message-ID: <48E4D8F3.1080300@cs.ntua.gr> Paulo S?rgio Almeida wrote: > > I noticed that the documentation of ets:tab2file/2 says: > > tab2file(Tab, Filename) -> ok | {error,Reason} > Filename = string() | atom() > > Shouldn't it be a name() instead as in the file module: > > name() = string() | atom() | DeepList > DeepList = [char() | atom() | DeepList] > > I tried using a deeplist and it works. In my opinion one should be careful not to repeat historical accidents that arguably are signs of bad programming language design. While I could possibly see some convenience arguments why one would want to allow a file name as something constructed out of a list of atoms and strings, so that one can e.g. write: -define(Application, myapp). %% Aren't macros great? -define(Suffix, ".erl"). then later Filename = [?Application, "_", myfile, ?Suffix], and finally use it in a call to: file:open(Filename, [read]) without having to go into the trouble to put a call to lists:concat/1 in between, I see very little reason to allow all possible combinations that the definition of DeepList above permits so that the following is also a valid file name: Filename = [this,['_',"is","_",a,"l",so,['_',["a",[], ['V',[a],[[l]]],id],'F',[i,l,e],"n",a,["me"]]]] In an ideal Erlang world, file names are just strings. Kostis From Rainer.Hansen Thu Oct 2 16:23:13 2008 From: Rainer.Hansen (Rainer Hansen) Date: Thu, 02 Oct 2008 16:23:13 +0200 Subject: [erlang-questions] Aachen-Euskirchen-Bonn Erlounge on Tuesday Message-ID: <20081002142313.126430@gmx.net> Welcome to the second Aachen-Euskirchen-Bonn Erlounge taking place in the Parkhotel in Euskirchen. We meet at 19:00 o'clock on October 7th, 2008. All Erlang developers and users are welcome to meet each other and talk about what you are doing. Homepage of Parkhotel Euskirchen: http://www.parkhotel-euskirchen.com/ You can get driving instructions by just typing Parkhotel Euskirchen into the Google search bar. The Parkhotel is very good to reach by public transport because it is opposite to the bus and train station in Euskirchen. Don't hesitate to contact me if you've got any questions or comments. Rainer Hansen -- Psssst! Schon vom neuen GMX MultiMessenger geh?rt? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger From michal Thu Oct 2 16:33:49 2008 From: michal (Michal Slaski) Date: Thu, 2 Oct 2008 16:33:49 +0200 Subject: [erlang-questions] =?iso-8859-1?q?ErlLounge_in_Krak=F3w=2C_Poland?= Message-ID: <047C0945-143B-4E8D-B9EB-A2AEE4A239F9@erlang-consulting.com> Hi, Tomorrow evening we are meeting for ErlLounge at 18.30 at Gwarek club which is close to the AGH University campus. Francesco Cesarini will be presenting about the history of Erlang. After the presentation there will be plenty of time to meet others who are interested in Erlang or are working with it every day. You can find more details here: http://www.erlang-consulting.com/erlang/events.html#68 Cheers, Michal -- Michal Slaski http://www.erlang-consulting.com From mbj Thu Oct 2 16:38:11 2008 From: mbj (Martin Bjorklund) Date: Thu, 02 Oct 2008 16:38:11 +0200 (CEST) Subject: [erlang-questions] Question about gen_event In-Reply-To: <48E3A2A6.4060007@cs.ntua.gr> References: <48E3A2A6.4060007@cs.ntua.gr> Message-ID: <20081002.163811.162288526.mbj@tail-f.com> Hi, Kostis Sagonas wrote: > I've been staring at the code of 'gen_event' and I cannot make much > sense of how the code for swapping handlers works. In fact, I am quite > convinced there is a bug in there but it is being silenced by the use of > a catch. Can somebody please confirm that this is a bug or enlighten me > on what's happening? > > The code of gen_event:do_swap/7 reads: > > do_swap(Mod1,Handler1,Args1,State1,Handler2,Args2,SName) -> > %% finalise the existing handler > State2 = do_terminate(...), > {Mod2,Handler} = new_handler(Handler2, Handler1), %% <--- This is correct; the module is extracted from Handler2, and the #handler{} is updated. > case catch Mod2:init({Args2, State2}) of > {ok, State2a} -> > {ok, Handler#handler{state = State2a}}; > Other -> > report_terminate(Handler2, crash, ...), %% <--- But this is wrong; Handler2 should be Handler here. Handler2 is either a module name (atom()) or a tuple {ModuleName, Id} ({atom(), term()}). But report_terminate wants a #handler{}. The variable names are pretty confusing... I suspect that once upon a time, Handler was just a modulename or the 2-tuple, and it has evolved into a record... /martin From jim.mccoy Thu Oct 2 19:28:29 2008 From: jim.mccoy (Jim McCoy) Date: Thu, 2 Oct 2008 10:28:29 -0700 Subject: [erlang-questions] Request to add md4 to crypto module Message-ID: After poking around a bit in the OTP sources it seems that it would be pretty trivial to add md4 to the crypto module. I will be testing a few patches later this week, but before I throw together a real EEP I was hoping that this might be a simple-enough change that the OTP team might consider adding it without the need for the formal process. As for the rationale: some applications (dhts, etc) need a large, fast hash that has a good uniqueness distribution but are not worried about the security implications of selecting an algorithm that is cryptographically weak. The md4 hash is about 50% faster than md5, which is a real win when you are hashing thousands of items. Since there are already "questionable" algorithms included in the crypto module (e.g. md5 and rc2) it seems that a warning in the docs that this algorithm should not be used for security-sensitive tasks would be sufficient notice to developers. Any thoughts or objections? jim From kostis Thu Oct 2 19:51:43 2008 From: kostis (Kostis Sagonas) Date: Thu, 02 Oct 2008 20:51:43 +0300 Subject: [erlang-questions] Erlang doesn't suck In-Reply-To: <20081002110518.8EC0A24064@relay.gooddata.com> References: <48E3A1E6.4090307@alertlogic.net> <9D9606A2-0064-471E-B214-9E82DC850982@gmail.com> <48E3A86A.8010508@alertlogic.net> <28B99EDD-C840-4E3F-B59C-77A89F371B12@gmail.com> <48E3E4FF.3020403@cs.ntua.gr> <20081002110518.8EC0A24064@relay.gooddata.com> Message-ID: <48E50A2F.2000102@cs.ntua.gr> Hynek Vychodil wrote: > I would like notice that hipe can cause performance lost for some > special cases. There is not simple equation, switch on hipe and you gain > some amount of performance surplus. Especially when you have tight loop > over not so much complex data structures you can gain big amount of > performance. It would have been much more helpful for the discussion if you presented some quantitative results (and preferably code) for your claims. For example, what qualifies as "not so much complex data structures" (by the way, have you measured what happens in "complex" ones?), "big amount", "performance loss for some special cases" (what's "special" about these special cases), etc. > When you do big amount of inter module calls you gain less This is slightly misleading: there is no "bad" treatment of inter module calls (other than that dictated by the semantics of hot code loading). What does have a non-negligible cost is so called mode-switching calls: calling interpreted code from native or vice versa. The simplest way to avoid this is to native compile everything. Alas, currently this is not so easy to do for standard libraries. But note that even without compiling everything, the speed up from native code is not something to disregard so quickly. For example, if I read Joel's mails correctly he got: 3000 games finished Elapsed: 181.960007s, Average run time: 0.060653335 seconds (for BEAM) Elapsed: 62.517129s, Average run time: 0.020839043 seconds (for HiPE) without compiling any of the OTP libraries. Joel can correct me if I am wrong here. > and when you do big amount of message passings you can lost some > preformance when switch it on. It would help more if, instead of rather unquantified statements, you or somebody else posted an actual application (*) showing a non-trivial performance loss when native compiled. It would at least give us something to work and improve upon. Kostis (*) not just a synthetic benchmark From joelr1 Thu Oct 2 20:22:22 2008 From: joelr1 (Joel Reymont) Date: Thu, 2 Oct 2008 19:22:22 +0100 Subject: [erlang-questions] Erlang doesn't suck In-Reply-To: <48E50A2F.2000102@cs.ntua.gr> References: <48E3A1E6.4090307@alertlogic.net> <9D9606A2-0064-471E-B214-9E82DC850982@gmail.com> <48E3A86A.8010508@alertlogic.net> <28B99EDD-C840-4E3F-B59C-77A89F371B12@gmail.com> <48E3E4FF.3020403@cs.ntua.gr> <20081002110518.8EC0A24064@relay.gooddata.com> <48E50A2F.2000102@cs.ntua.gr> Message-ID: <0A69EEEF-0673-4373-8E9A-B8077242302A@gmail.com> Kostis, On Oct 2, 2008, at 6:51 PM, Kostis Sagonas wrote: > For example, if I read Joel's mails correctly he got: > > 3000 games finished > Elapsed: 181.960007s, Average run time: 0.060653335 seconds (for BEAM) > Elapsed: 62.517129s, Average run time: 0.020839043 seconds (for HiPE) The difference between HiPE and BEAM was not pronounced at all, 10-15% if I remember correctly. The difference above is between Solaris/ Nevada and my Mac Pro. Thanks, Joel -- wagerlabs.com From kostis Thu Oct 2 20:27:49 2008 From: kostis (Kostis Sagonas) Date: Thu, 02 Oct 2008 21:27:49 +0300 Subject: [erlang-questions] Erlang doesn't suck In-Reply-To: <48E50C41.6030305@alertlogic.net> References: <48E3A1E6.4090307@alertlogic.net> <9D9606A2-0064-471E-B214-9E82DC850982@gmail.com> <48E3A86A.8010508@alertlogic.net> <28B99EDD-C840-4E3F-B59C-77A89F371B12@gmail.com> <48E3E4FF.3020403@cs.ntua.gr> <20081002110518.8EC0A24064@relay.gooddata.com> <48E50A2F.2000102@cs.ntua.gr> <48E50C41.6030305@alertlogic.net> Message-ID: <48E512A5.6030601@cs.ntua.gr> Paul Fisher wrote: > Kostis Sagonas wrote: >>> When you do big amount of inter module calls you gain less >> >> This is slightly misleading: there is no "bad" treatment of inter module >> calls (other than that dictated by the semantics of hot code loading). >> What does have a non-negligible cost is so called mode-switching calls: >> calling interpreted code from native or vice versa. The simplest way to >> avoid this is to native compile everything. Alas, currently this is not >> so easy to do for standard libraries. > > Wow, this is a wonderful nugget of information. I had not considered > that the transition is the real performance killer... > > Just to clarify, I should expect performance from fastest to slowest to be: > > 1) inter-module HiPE -> HiPE > 2) inter-module BEAM -> BEAM > 3) inter-module HiPE -> BEAM or inter-module BEAM -> HiPE > > right? right Kostis From yoursurrogategod Thu Oct 2 22:34:07 2008 From: yoursurrogategod (YourSurrogateGod) Date: Thu, 2 Oct 2008 13:34:07 -0700 (PDT) Subject: [erlang-questions] GTK bindings In-Reply-To: <48E4B148.4060901@gmail.com> References: <2ae3549f-f1cb-4e3c-b7e3-d805c6de372a@m36g2000hse.googlegroups.com> <48CFF05B.90401@lionet.info> <15b6a55b-956f-45c8-b412-76751fe630ab@e53g2000hsa.googlegroups.com> <087d239c-07b5-47ef-9372-ae097ca12bcd@m45g2000hsb.googlegroups.com> <3dbc6d1c0809161457v2ed4f29bxe16bcc124dbf06f5@mail.gmail.com> <14f0e3620809161547x32377a37ke4c9abee0a8c41e1@mail.gmail.com> <3dbc6d1c0809161643t33fb3a80l7cb4b330333a1ef7@mail.gmail.com> <4ac8254d0809170244s4ebd31b1y4d0b361cdf3cb76f@mail.gmail.com> <48D1FC87.8030601@it.uu.se> <48E0C70D.5020700@gmail.com> <48E3AD6F.5050909@gmail.com> <48E3B568.2010702@gmail.com> <68918cba-a4cd-45bd-a47b-50684819ca16@m45g2000hsb.googlegroups.com> <48E4B148.4060901@gmail.com> Message-ID: Oh, that's fine. I'm just curious how everything looks internally in that file and what commands are used. On Oct 2, 7:32?am, Serge Aleynikov wrote: > Actually it turned out that the server I was running it on had several > versions of pango, cairo, gtk+, x11, xml and other dependencies, so I > had to play with settings to enforce selection of alternative libraries > until I got it to work. > > YourSurrogateGod wrote: > > Could you please show your Makefile? > > > On Oct 1, 1:37 pm, Serge Aleynikov wrote: > >> Actually I poked around with the makefile settings for gtknode and > >> somehow the problem went away... > > _______________________________________________ > erlang-questions mailing list > erlang-questi...://www.erlang.org/mailman/listinfo/erlang-questions From vychodil.hynek Thu Oct 2 22:51:10 2008 From: vychodil.hynek (Hynek Vychodil) Date: Thu, 2 Oct 2008 22:51:10 +0200 Subject: [erlang-questions] Erlang doesn't suck In-Reply-To: <48E50A2F.2000102@cs.ntua.gr> References: <48E3A1E6.4090307@alertlogic.net> <9D9606A2-0064-471E-B214-9E82DC850982@gmail.com> <48E3A86A.8010508@alertlogic.net> <28B99EDD-C840-4E3F-B59C-77A89F371B12@gmail.com> <48E3E4FF.3020403@cs.ntua.gr> <20081002110518.8EC0A24064@relay.gooddata.com> <48E50A2F.2000102@cs.ntua.gr> Message-ID: <20081002205111.9A9E32407D@relay.gooddata.com> On Thu, Oct 2, 2008 at 7:51 PM, Kostis Sagonas wrote: > Hynek Vychodil wrote: > >> I would like notice that hipe can cause performance lost for some special >> cases. There is not simple equation, switch on hipe and you gain some amount >> of performance surplus. Especially when you have tight loop over not so much >> complex data structures you can gain big amount of performance. >> > > It would have been much more helpful for the discussion if you presented > some quantitative results (and preferably code) for your claims. For > example, what qualifies as "not so much complex data structures" (by the > way, have you measured what happens in "complex" ones?), "big amount", > "performance loss for some special cases" (what's "special" about these > special cases), etc. My experience coming from first Wide Finder Project, Cedric Beust's challenge and some other works. I was busy to make some worth synthetic tests which only is valuable in this array, I think. My observation is that HiPE gain strongly depend on how task is solved. The fastest BEAM solution of some nontrivial task is often different from fastest HiPE solution. And from another point of view, same code compiled using HiPE can vary from 30 times faster to 20% slower. It means, that for some modules from OTP switching on HiPE can be worth thing (for nondebug environment only) but only for some modules, not for all. > > > When you do big amount of inter module calls you gain less >> > > This is slightly misleading: there is no "bad" treatment of inter module > calls (other than that dictated by the semantics of hot code loading). What > does have a non-negligible cost is so called mode-switching calls: calling > interpreted code from native or vice versa. The simplest way to avoid this > is to native compile everything. Alas, currently this is not so easy to do > for standard libraries. But note that even without compiling everything, > the speed up from native code is not something to disregard so quickly. > > For example, if I read Joel's mails correctly he got: > > 3000 games finished > Elapsed: 181.960007s, Average run time: 0.060653335 seconds (for BEAM) > Elapsed: 62.517129s, Average run time: 0.020839043 seconds (for HiPE) > > without compiling any of the OTP libraries. Joel can correct me if I am > wrong here. > > and when you do big amount of message passings you can lost some >> preformance when switch it on. >> > > It would help more if, instead of rather unquantified statements, you or > somebody else posted an actual application (*) showing a non-trivial > performance loss when native compiled. It would at least give us something > to work and improve upon. > > Kostis > > (*) not just a synthetic benchmark > Why not synthetic benchmark? My experience is that good synthetic benchmark is far worthy than "real" application because exactly point where is problem and which way is faster. I know, it is worthy only for one which understand. Application benchmarks are usefull just only for marketing and looks good in PR materials. They allege only how thing works for one special task and it solution, they tells nothink how it will works for a little bit different solution or task. Synthetic benchmarks contrary tell how work each component and you can predict how it will work in different tasks and solutions. It is harder, may be not so modern, but good engeneering. -- --Hynek (Pichi) Vychodil -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081002/2607a4d2/attachment-0001.html From alexander.uvarov Thu Oct 2 23:29:09 2008 From: alexander.uvarov (Alexander) Date: Fri, 3 Oct 2008 03:29:09 +0600 Subject: [erlang-questions] Request to add md4 to crypto module In-Reply-To: References: Message-ID: <200810030329.09362.alexander.uvarov@gmail.com> On Thursday 02 October 2008 23:28:29 Jim McCoy wrote: > After poking around a bit in the OTP sources it seems that it would be > pretty trivial to add md4 to the crypto module. I will be testing a > few patches later this week, but before I throw together a real EEP I > was hoping that this might be a simple-enough change that the OTP team > might consider adding it without the need for the formal process. +1 for enhancement, also it would be useful to have DES in ECB mode too (trivial). If someone interested, there is my implementation based on erlang crypto driver (md4, des in ecb mode - used by mschapv2) http://pastie.org/283903 Also, why not make MD2 and finish dance with MD* crypto in erlang? :) > > As for the rationale: some applications (dhts, etc) need a large, fast > hash that has a good uniqueness distribution but are not worried about > the security implications of selecting an algorithm that is > cryptographically weak. The md4 hash is about 50% faster than md5, > which is a real win when you are hashing thousands of items. Since > there are already "questionable" algorithms included in the crypto > module (e.g. md5 and rc2) it seems that a warning in the docs that > this algorithm should not be used for security-sensitive tasks would > be sufficient notice to developers. > > Any thoughts or objections? > > jim > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions From greg.burri Thu Oct 2 23:59:47 2008 From: greg.burri (Greg Burri) Date: Thu, 2 Oct 2008 23:59:47 +0200 Subject: [erlang-questions] Mnesia:write, index and complexity Message-ID: <60ed8a460810021459q28b33bbct15cdd8702a403861@mail.gmail.com> Hi, I use mnesia for a little project and I observed a strange (but maybe right) behavior from the function mnesia:write/1 when an extra index has alway the same value. In this case the complexity of the insertion appears to be in O(n) where n is the number of tuple in the table. My record : -record(minichat, { id, auteur_id, %indexed date, pseudo, contenu, troll_id = undefined, %indexed racine_id = undefined }). So, I made a little benchmark to see what happen in three cases : 1) '#minichat.troll_id' is undefined for all tuple 2) same as 1) but without the index on 'troll_id' 3) 'troll_id' is indexed but some random values are put in it You can see the results here : 1) O(n) : http://www.gburri.org/mnesia_write/results_100_000.png 2) O(1) : http://www.gburri.org/mnesia_write/results_100_000_without_index_on_troll_id.png 3) O(1) : http://www.gburri.org/mnesia_write/results_100_000_with_random_data_into_troll_id.png Is this behavior normal ? Is this the result of the collisions of keys ? Here is some additional informations about my tests : The creation of the table (called at the beginning of all test) : [..] mnesia:create_table(minichat, [ {attributes, record_info(fields, minichat)}, {disc_copies, [node()]} ]), mnesia:add_table_index(minichat, auteur_id), mnesia:add_table_index(minichat, troll_id). % commented for the second case test The benchmark code : [..] bench_write_minichat(Filename) -> Times = bench_write_minichat(1, []), {ok, File} = file:open(Filename, [write]), lists:foreach( fun({Id, Time}) -> io:format(File, "~w ~w~n", [Id, Time]) end, Times ), file:close(File). bench_write_minichat(100000, Temps) -> Temps; bench_write_minichat(Id, Temps) -> {T, _} = timer:tc(mnesia, transaction, [fun() -> mnesia:write(#minichat{ id = Id, auteur_id = random:uniform(1000), date = now(), pseudo = "Test", contenu = "Blabla blabla bla.", racine_id = random:uniform(1000) % ,troll_id = random:uniform(1000) % uncommented for the third case test }) end]), bench_write_minichat(Id + 1, if Id rem 500 =:= 0 -> [{Id, T} | Temps]; true -> Temps end). /Greg Burri -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081002/52c185e9/attachment.html From btolputt Thu Oct 2 09:23:58 2008 From: btolputt (Benjamin Tolputt) Date: Thu, 02 Oct 2008 17:23:58 +1000 Subject: [erlang-questions] The Erlang Rationale In-Reply-To: References: <3dbc6d1c0809291502m3ad2147djfdc652a8e5c7a157@mail.gmail.com> <48E1F395.5040501@gmail.com> <3dbc6d1c0809300519kd46dbadsdfb670f71865b5@mail.gmail.com> <48E21D43.1040509@gmail.com> <4ac8254d0809300609m7c72c6b2je9774a70c629acf8@mail.gmail.com> <3dbc6d1c0809300630q35221794jf0922f370de6dd04@mail.gmail.com> <6c2563b20810010649xdb362dcyefc9e361608b33f7@mail.gmail.com> Message-ID: <48E4770E.7040303@bigpond.net.au> Richard O'Keefe wrote: > Nice logging example The problem I see with your solution(s) is that they are only better if the Erlang were different (i.e. top level variables and ?HERE). This, to me, is just a game of "what if" (unless you re actually putting them into Erlang - in which case, I humbly apologise). "What if" scenarios are great and all, but don't actually a valid argument make. -- Regards, Benjamin Tolputt Analyst Programmer Mob: 0417 456 505 Email: btolputt This email and any files transmitted with it are confidential to the intended recipient and may be privileged. If you have received this email inadvertently or you are not the intended recipient, you may not disseminate, distribute, copy or in any way rely on it. Further, you should notify the sender immediately and delete the email from your computer. Whilst we have taken precautions to alert us to the presence of computer viruses, we cannot guarantee that this email and any files transmitted with it are free from such viruses. From pablo.polvorin Fri Oct 3 01:36:46 2008 From: pablo.polvorin (Pablo Polvorin) Date: Thu, 2 Oct 2008 20:36:46 -0300 Subject: [erlang-questions] Mnesia:write, index and complexity In-Reply-To: <60ed8a460810021459q28b33bbct15cdd8702a403861@mail.gmail.com> References: <60ed8a460810021459q28b33bbct15cdd8702a403861@mail.gmail.com> Message-ID: <1ffe809c0810021636t513aaebeq32d413011d48822c@mail.gmail.com> Hi, there has been a discussion of this some months ago, search for "Index Overhead In Mnesia" 2008/10/2 Greg Burri : > Hi, > I use mnesia for a little project and I observed a strange (but maybe right) > behavior from the function mnesia:write/1 when an extra index has alway the > same value. > In this case the complexity of the insertion appears to be in O(n) where n > is the number of tuple in the table. > > My record : > -record(minichat, > { > id, > auteur_id, %indexed > date, > pseudo, > contenu, > troll_id = undefined, %indexed > racine_id = undefined > }). > > So, I made a little benchmark to see what happen in three cases : > 1) '#minichat.troll_id' is undefined for all tuple > 2) same as 1) but without the index on 'troll_id' > 3) 'troll_id' is indexed but some random values are put in it > > You can see the results here : > 1) O(n) : http://www.gburri.org/mnesia_write/results_100_000.png > 2) O(1) : > http://www.gburri.org/mnesia_write/results_100_000_without_index_on_troll_id.png > 3) O(1) : > http://www.gburri.org/mnesia_write/results_100_000_with_random_data_into_troll_id.png > > Is this behavior normal ? Is this the result of the collisions of keys ? > > > Here is some additional informations about my tests : > > The creation of the table (called at the beginning of all test) : > [..] > mnesia:create_table(minichat, [ > {attributes, record_info(fields, minichat)}, > {disc_copies, [node()]} > ]), > mnesia:add_table_index(minichat, auteur_id), > mnesia:add_table_index(minichat, troll_id). % commented for the second > case test > > The benchmark code : > [..] > bench_write_minichat(Filename) -> > Times = bench_write_minichat(1, []), > {ok, File} = file:open(Filename, [write]), > lists:foreach( > fun({Id, Time}) -> > io:format(File, "~w ~w~n", [Id, Time]) > end, > Times > ), > file:close(File). > bench_write_minichat(100000, Temps) -> Temps; > bench_write_minichat(Id, Temps) -> > {T, _} = timer:tc(mnesia, transaction, [fun() -> > mnesia:write(#minichat{ > id = Id, > auteur_id = random:uniform(1000), > date = now(), > pseudo = "Test", > contenu = "Blabla blabla bla.", > racine_id = random:uniform(1000) > % ,troll_id = random:uniform(1000) % uncommented for the third case > test > }) > end]), > bench_write_minichat(Id + 1, if Id rem 500 =:= 0 -> [{Id, T} | Temps]; > true -> Temps end). > > > /Greg Burri > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From pfisher Wed Oct 1 21:09:52 2008 From: pfisher (Paul Fisher) Date: Wed, 01 Oct 2008 14:09:52 -0500 Subject: [erlang-questions] Erlang doesn't suck In-Reply-To: <28B99EDD-C840-4E3F-B59C-77A89F371B12@gmail.com> References: <48E3A1E6.4090307@alertlogic.net> <9D9606A2-0064-471E-B214-9E82DC850982@gmail.com> <48E3A86A.8010508@alertlogic.net> <28B99EDD-C840-4E3F-B59C-77A89F371B12@gmail.com> Message-ID: <48E3CB00.1030104@alertlogic.net> Joel Reymont wrote: > On Oct 1, 2008, at 5:42 PM, Paul Fisher wrote: > >> Which begs the question of whether you compile to native or not for >> your benchmarking? Not everything benefits, but we have some >> modules that show significant gains from: >> >> -compile([native, {hipe,[o3]}, inline]). > > > There's certainly an increase in throughput (request per second) with > hipe, even under 32 bits. > > Is there a way to mass-hipe-compile all of OTP? I'd love to know if there is. > > Elapsed: 62.517129s, Average run time: 0.020839043 seconds > > Now I have to try to compile R12B4 in 64-bit mode.... I'm pulling together patch/instructions to make it all work and will send soon. -- paul From ok Fri Oct 3 03:44:24 2008 From: ok (Richard O'Keefe) Date: Fri, 3 Oct 2008 14:44:24 +1300 Subject: [erlang-questions] The Erlang Rationale In-Reply-To: <6c2563b20810012355t5ea248a0q24deddcd415a85fe@mail.gmail.com> References: <3dbc6d1c0809291502m3ad2147djfdc652a8e5c7a157@mail.gmail.com> <48E1F395.5040501@gmail.com> <3dbc6d1c0809300519kd46dbadsdfb670f71865b5@mail.gmail.com> <48E21D43.1040509@gmail.com> <4ac8254d0809300609m7c72c6b2je9774a70c629acf8@mail.gmail.com> <3dbc6d1c0809300630q35221794jf0922f370de6dd04@mail.gmail.com> <6c2563b20810010649xdb362dcyefc9e361608b33f7@mail.gmail.com> <6c2563b20810012355t5ea248a0q24deddcd415a85fe@mail.gmail.com> Message-ID: On 2 Oct 2008, at 7:55 pm, Edwin Fine wrote: > Sorry, but I did not agree. You agreed that macros *CAN* make maintenance harder. That's enough agreement for me. > You just read it that way. What I perhaps should have written is > that you bluntly asserted that macros make maintenance harder. I am > bluntly asserting that it is not necessarily so. My claim is that macros *always* makes it harder to build intelligent maintenance support tools. > > just like gotos *can* create spaghetti code. Neither of them are > intrinsically bad, merely easy to misuse. The existence of essentially uncontrolled gotos in a language makes optimising compilation harder; the task of building a compiler for such a language is more difficult *whether the feature is used or not*. In the same way, the *possibility* of macros makes it harder to build support tools, whether they are used or not, no matter what degree of discipline might be involved. Of course Erlang still isn't as weird as C, where /??\ * this *??\ /// was a comment As it happens, I straddle the fence on gotos. I have a compiler for a language with no gotos (and in which I never miss them); the compiler generates C with gotos (where they are used in a particular stylised way to avoid code duplication). But I maintain a version of AWK, and one of the things I did in that was to hunt down the gotos one after another. In fact, I'm still doing it. While writing this message I just zapped five more. (They were there for a micro-optimisation that made sense 30 years ago, but is now routinely done by compilers. The code is *definitely* easier to understand without them.) > I don't think this is a particularly compelling argument. I've been > involved in maintenance of multi-million line systems and had much > bigger fish to fry than macro-related difficulties with cross- > reference tools. Maybe your experience has been different. I have repeatedly encountered serious difficulties in navigating other people's macro-heavy code. > Used with care and discipline, they both arguably have a place in > good programming practice. Remember, MY "care and discipline" is YOUR "spaghetti code". [I was going to say it the other way around, but decided that might sound insulting.] I have chunks of C code generated by AWK scripts. (There's a Haskell compiler written in C where large chunks were generated by Perl scripts.) I happen to think this is not only cool, but counts as "care and discipline". Someone whose IDE hasn't the slightest clue and can't really cope with such stuff (XCode certainly isn't much help with colouring C code inside AWK strings (:-)) will not be impressed. > > > As a matter of fact, I still use M4 on Java code. > (Remember, Java 1.5 generics do *not* accept primitive types > as arguments. If you want to do that without the very heavy > overhead of Java boxing and unboxing, M4 is the only game in town.) > > So macros are NOT that evil :) Macros are indeed like gotos: when you aren't given the *right* tools for the job (something rather like Haskell/Clean/ Mercury/BitC typeclasses), macros are better than nothing. But something built into the language (counting the Dialyzer, which can read and check -spec declarations for functions but not for ?macros), is generally better. > > But what if, instead of or in addition to ?MODULE and ?LINE, > the system provided you with ?HERE, expanding to > {Module, Line, {Function, Arity}}. Then > > iutil_log:flog(?HERE, "Received ~p from ~p~n", [Msg,Socket]) > > doesn't seem _that_ horrible. > > Sorry to belabor the point, but what if it did? It doesn't. What if > we all lived in peace and harmony and respected each other's rights? Two answers. First, adding ?HERE to 'epp' is no big deal. Second, we don't actually need it. In your debug.hrl file, have -compile({inline, [{debug,0},{flog,3}]}). debug() -> true. % or false, whatever. flog(L, F, A) -> case debug() of true -> iutil_log:log_debug(?MODULE, L, F, A) ; false -> ok end. And now all you need to get what you had before is flog(?LINE, "Received ~p from ~p~n", [Msg,Socket]) where the ?MODULE part is supplied automatically. > Suppose we had top-level variables instead. So > > But we don't. I wish we did. Agreement again. One of the reasons we *don't* have top level variables is that we were given the preprocessor *instead*. Another strike against it. However, thanks to inlining, we don't actually need them for this problem. > > True - but I was working towards my ultimate point that having to > recompile is a pain and wanted the ability to change run-time log > levels. Which I dealt with later in the message. > And, using the above code, won't you get copious compiler or > Dialyzer warnings complaining that only one branch of the case will > ever be reached? How would you suppress those? Or are you going to > invent a suitable -pragma() for Erlang :) ? You're right that Dialyzer complains here. This is precisely as annoying, and precisely as (un)helpfl, as the way Lint started to warning about "constant conditional" in the do { ... } while (0) construction. If a case or if has *no* matching arms, that's a failure, but if *some* arms don't match, that's not a failure, it's just constant propagation. What's really annoying is that adding the declaration -spec(debug/0 :: () -> bool()). -- which I expected to tell Dialyzer that although *this* version of debug/0 can't return 'false', another version might -- didn't help at all. Shouldn't this *be* the pragma we need here? (Dialyzer v1.8.1) > > Ah, the old I've-seen-crap-code trick. Yes, absolutely true, and > anyone worth their salt will never put important code into log > statements that won't get evaluated. Which means that the argument for using a macro here completely disappears. > > -inline([flog/3]). > flog(Where, Format, Arguments) when Debug -> %%% Huh?? > > case iutil_log:ok_to_log(debug) > of true -> > {Module, Line, _} = Where, > iutil:log_debug(Module, Line, Format, Arguments) > ; false -> > ok > end; > flog(_, _, _) -> > ok. > > ... flog(?HERE, "......", [.....]) ... > > would push the evaluation of the format and arguments into the one > case branch that uses them. If it doesn't, we have far worse > performance issues to worry about than this one. > > Where does Debug come from? Is it a (non-existent) top-level variable? Please. We are picking nits here. So I edited the wrong version. flog(Line, Format, Arguments) -> case debug() of false -> ok ; true-> case iutil_log:ok_to_log(debug) of false -> ok ; true -> iutil_log:log_debug(?MODULE, Line, Format, Arguments) end end. > > In this context, I find BitC's distinction between pure and impure > functions _in the type system_ interesting. > > That would be very useful - does that mean the compiler > automatically flags functions as pure or impure based on their side- > effects? Yes. The draft manual gives the example of inferring that map :: %e fn (%e fn a -> b) list(a) -> list(b) -- I can't quite recall the syntax -- a call to map(f, xs) has side effects if and only if a call to f has. > > > That's also its strength (to be able to do ANYTHING and you don't > have to change the code). To find the definition using find and grep > isn't *that* hard, is it? I have searched the entire Erlang source > code base for things of interest in under a minute with find/grep. > Maybe it's slow using that 500MHz UltraSparc you are saddled with :( It's actually a 2.16 Intel Core 2 Duo intel-Mac that I've been running Erlang on recently. Grep is nice, but it doesn't understand about comments, it doesn't understand the difference between f(X) and f(X, Y), and a whole bunch of other things which explain why we have an Erlang cross-reference program. > If only we had ?HERE, > But we don't. I have to work with the real world. If ?HERE was here > I would use it! A prototype implementation of ?HERE, where it expands to {?MODULE,?LINE,undefined}, is just this much of a change to epp.erl: < Ms30 = dict:store({atom,'HERE'}, {none,[ < {'{',1},{'?',1},{atom,1,'MODULE'}, < {',',1},{'?',1},{atom,1,'LINE'}, < {',',1},{atom,1,undefined},{'}',1}]}, Ms3), < Ms31 = dict:store({atom,'MODULE_STRING'}, undefined, Ms30), --- > Ms31 = dict:store({atom,'MODULE_STRING'}, undefined, Ms3), Making it add ?LINE in as well would be trivial. To get function information requires parser support, so I'd have the preprocessor expand it to a {location, Line_Number, File_Name, Module} token, and then have the parser recognise this and generate the appropriate data structure. I suspect that I would have the parser turn it into a new {location...} AST form, and then another pass would deal with it. The issues are (1) finishing the design. Exactly what information should we put in a location? EEP time, except I don't have time today. (2) writing the code. Given my unfamiliarity with the compiler, this would probably take me two days to code and test. (3) documenting it. Hunting down all the files that need changing would be the tricky bit. (4) fixing all the code that currently thinks it knows exactly what the lexical analyser and parser can produce. This is the really hard bit. > The one important thing that I perhaps didn't understand from your > discussion is how you proposed to change the logging level at run > time, given the *existing* features of Erlang. With plain ordinary run-time code, how else? Didn't you see the "case iutil_log:ok_to_log(debug)" line? > > Understand that I gave the LOG_DBG macro as an example. As it > happens, I have LOG_TRACE, LOG_INFO, LOG_WARN, and LOG_ERROR as well. Which can presumably all be done the same way. To someone writing this code from scratch today, using functions is _less_ effort (because better understood by editing and debugging tools) than using macros. With *no* additions to the language. (Except for getting Dialyzer to shut up.) > Let me tell you what I have done, and this will probably give you > nightmares because it's a terrible hack, but it works well. Actually, no. It was the obvious thing to do. While I too suspect that it's probably faster than using the process dictionary, it might be a good idea to measure it. Ironically, you have actually provided a good example of why functions are *better* than macros for this kind of thing. You *can* hot-load a replacement for an imported function, but you *can't* hot-load a replacement for an included macro. (Nor can you set breakpoints on macros.) What I mean by a "top-level variable" is not something mutable. It's simply an Erlang variable bound at the top level of a module. A named constant, in other words. Although it would be nice to export and import top level variables; your hot-loading trick would still apply (and maybe even be a touch faster). From ok Fri Oct 3 04:15:29 2008 From: ok (Richard O'Keefe) Date: Fri, 3 Oct 2008 15:15:29 +1300 Subject: [erlang-questions] The Erlang Rationale In-Reply-To: <48E4770E.7040303@bigpond.net.au> References: <3dbc6d1c0809291502m3ad2147djfdc652a8e5c7a157@mail.gmail.com> <48E1F395.5040501@gmail.com> <3dbc6d1c0809300519kd46dbadsdfb670f71865b5@mail.gmail.com> <48E21D43.1040509@gmail.com> <4ac8254d0809300609m7c72c6b2je9774a70c629acf8@mail.gmail.com> <3dbc6d1c0809300630q35221794jf0922f370de6dd04@mail.gmail.com> <6c2563b20810010649xdb362dcyefc9e361608b33f7@mail.gmail.com> <48E4770E.7040303@bigpond.net.au> Message-ID: <3A1A577F-46AF-4923-A327-3B36238CB116@cs.otago.ac.nz> On 2 Oct 2008, at 8:23 pm, Benjamin Tolputt wrote: > Richard O'Keefe wrote: >> Nice logging example > > The problem I see with your solution(s) is that they are only better > if > the Erlang were different (i.e. top level variables and ?HERE). Wrong, as I realised after posting it. In fact, >>>>in that very posting<<<< I showed how top level variables are >>>not<<< in fact needed. Let me offer the skeleton again, slightly generalised. -compile({inline, [{compile_time_debug_level,0}, {log_error,3}, {log_warning,3}]}). compile_time_debug_level() -> errors. log_error(L, F, A) -> logger:log(error, ?MODULE, L, F, A). log_warning(L, F, A) -> case compile_time_debug_level() of warnings -> logger:log(warning, ?MODULE, L, F, A) ; errors -> ok end. called as ... log_error(?LINE, "...", [...]) ... ... log_warning(?LINE, "...", [...]) ... where ?LINE is sufficient because after -include processing, the local log functions are in the same module as the caller, so ?MODULE doesn't need to be passed. > This, to > me, is just a game of "what if" (unless you re actually putting them > into Erlang - in which case, I humbly apologise). "What if" scenarios > are great and all, but don't actually a valid argument make. You have completely mistaken the form of my argument at the point. My argument had the implicit form (which I thought to be so very obvious given good will as to not need spelling out) GRANTED for the sake of argument that logging of this form is something not currently well served, WHAT WOULD WE NEED TO DO in order to remove any need to use the preprocessor for this purpose. I first considered a run-time method of discovering the caller's location and dismissed it. I then mentioned top-level variables BUT SHOWED HOW WE DON'T NEED THEM. (Although it would be nice if the Dialyzer were more tolernate of the resulting code.) I then mentioned ?HERE as a possible idea that would leave the source code with a visible mention of "at this point I pass my source location" -- hence would be more tokens to type than using a macro -- but in a much shorter and potentially richer form than ?MODULE, ?LINE. Given my history of writing EEPS, readers were expected to see this as a pre-pre-EEP for ?HERE. Today I've mailed out patches to add a prototype version of ?HERE that gives you {?MODULE,?LINE,undefined} with undefined as a place-holder for a future {function,arity}. However, on the way home last night, it became annoyingly obvious that we don't actually need ?HERE at all. If people are content with ?MODULE and ?LINE, they can get that right now, passing ?LINE in the call and supplying ?MODULE in the (-included) callee. Note that when I complain about what macros do to maintainability -- including the ability of editors to indent properly -- I am *not* arguing against -include or even against ?MODULE and ?LINE or any other compiler-generated context-sensitive named constants, which turn out to be more abundant than I had remembered. This is a textbook case of why "no, we have to deal with the language as it is" is very bad thinking. Erlang is open source. We DON'T have to stick with the language as it is. We can all, any of us, invent alternatives and write EEPS. Having said "I need macros to do X", it is not helpful to just rest there. One should say "Have I really identified a need for macros or is there another way to do it? If I have really identified a need, what changes to the language or system would eliminate that need?" Come to think of it, my first (rejected) idea, of picking up the location at run time, might *long term* be the very best idea of all. (Or, on the other hand, it might still be as stunningly bad as I first thought it. I was inspired by the nargs() function that was available in some versions of C.) One of the issues that keeps coming up each year is someone wanting better location information in errors messages and tracebacks, and digging that out at run time seems to be the only practical way to do it. That being done, we wouldn't need ?MODULE, ?FILE, ?LINE, or any of those things; we could pick them up at run time. (Anyone else out there remember the B6700? 1960s design mainframe and operating system, but run-time errors *routinely* gave you line numbers in tracebacks.) From saleyn Fri Oct 3 04:32:37 2008 From: saleyn (Serge Aleynikov) Date: Thu, 02 Oct 2008 22:32:37 -0400 Subject: [erlang-questions] otp.net Message-ID: <48E58445.6050806@gmail.com> While playing with the otp.net project for the past several days I ran into one problem that I can't quite explain. I am starting a .NET node (saleyn) and connecting to a regular Erlang node (a), then send a Pid from .NET to Erlang and try to set up a monitor. The monitor call fails with badarg: (a)2> register(test, self()). true (a)3> nodes(hidden). [saleyn] (a)4> f(M), M = receive M -> M end. <5852.1.0> (a)5> M ! {hello, self()}. {hello,<0.50.0>} (a)6> erlang:monitor(process, M). ** exception error: bad argument in function erlang:monitor/2 called as erlang:monitor(process,<5852.1.0>) (a)7> I am able to send messages back and forth between two nodes and verify their delivery, but don't understand why the monitor call would fail. Does anyone have a clue? Serge From devdoer2 Fri Oct 3 06:08:46 2008 From: devdoer2 (devdoer bird) Date: Fri, 3 Oct 2008 12:08:46 +0800 Subject: [erlang-questions] Will mnesia transaction abort when the process who start it exits? Message-ID: HI: When the process start a mnesia transaction exits, will the transaction abort? If the mnesia database operation is NOT in a transaction, will the mnesia operation abort when the start process exit? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081003/11249737/attachment.html From lloy0076 Wed Oct 1 05:55:45 2008 From: lloy0076 (David Lloyd) Date: Wed, 01 Oct 2008 13:25:45 +0930 Subject: [erlang-questions] Simple OTP Question... In-Reply-To: References: <48E2E75E.4020000@adam.com.au> Message-ID: <48E2F4C1.9030202@adam.com.au> Damn, Maxim Treskin wrote: > Just read `erl -man gen_server`. > > ====== > start(ServerName, Module, Args, Options) -> Result > ServerName = {local, Name} | {global, GlobalName} > ====== > ServerName is NOT {ok, Name} > >> However, if I remove the "true, " in the source, the gen_server starts. > Which of? Thanks - I was looking for a more complex error when it should have been staring me in the face :( DSL From greg.burri Fri Oct 3 07:35:28 2008 From: greg.burri (Greg Burri) Date: Fri, 3 Oct 2008 07:35:28 +0200 Subject: [erlang-questions] Mnesia:write, index and complexity In-Reply-To: <1ffe809c0810021636t513aaebeq32d413011d48822c@mail.gmail.com> References: <60ed8a460810021459q28b33bbct15cdd8702a403861@mail.gmail.com> <1ffe809c0810021636t513aaebeq32d413011d48822c@mail.gmail.com> Message-ID: <60ed8a460810022235k3fa0a359tbc850a4d6cb7604c@mail.gmail.com> Thanks a lot, I solved my problem... /Greg On Fri, Oct 3, 2008 at 1:36 AM, Pablo Polvorin wrote: > Hi, > there has been a discussion of this some months ago, > search for "Index Overhead In Mnesia" > > > 2008/10/2 Greg Burri : > > Hi, > > I use mnesia for a little project and I observed a strange (but maybe > right) > > behavior from the function mnesia:write/1 when an extra index has alway > the > > same value. > > In this case the complexity of the insertion appears to be in O(n) where > n > > is the number of tuple in the table. > > > > My record : > > -record(minichat, > > { > > id, > > auteur_id, %indexed > > date, > > pseudo, > > contenu, > > troll_id = undefined, %indexed > > racine_id = undefined > > }). > > > > So, I made a little benchmark to see what happen in three cases : > > 1) '#minichat.troll_id' is undefined for all tuple > > 2) same as 1) but without the index on 'troll_id' > > 3) 'troll_id' is indexed but some random values are put in it > > > > You can see the results here : > > 1) O(n) : http://www.gburri.org/mnesia_write/results_100_000.png > > 2) O(1) : > > > http://www.gburri.org/mnesia_write/results_100_000_without_index_on_troll_id.png > > 3) O(1) : > > > http://www.gburri.org/mnesia_write/results_100_000_with_random_data_into_troll_id.png > > > > Is this behavior normal ? Is this the result of the collisions of keys ? > > > > > > Here is some additional informations about my tests : > > > > The creation of the table (called at the beginning of all test) : > > [..] > > mnesia:create_table(minichat, [ > > {attributes, record_info(fields, minichat)}, > > {disc_copies, [node()]} > > ]), > > mnesia:add_table_index(minichat, auteur_id), > > mnesia:add_table_index(minichat, troll_id). % commented for the second > > case test > > > > The benchmark code : > > [..] > > bench_write_minichat(Filename) -> > > Times = bench_write_minichat(1, []), > > {ok, File} = file:open(Filename, [write]), > > lists:foreach( > > fun({Id, Time}) -> > > io:format(File, "~w ~w~n", [Id, Time]) > > end, > > Times > > ), > > file:close(File). > > bench_write_minichat(100000, Temps) -> Temps; > > bench_write_minichat(Id, Temps) -> > > {T, _} = timer:tc(mnesia, transaction, [fun() -> > > mnesia:write(#minichat{ > > id = Id, > > auteur_id = random:uniform(1000), > > date = now(), > > pseudo = "Test", > > contenu = "Blabla blabla bla.", > > racine_id = random:uniform(1000) > > % ,troll_id = random:uniform(1000) % uncommented for the third > case > > test > > }) > > end]), > > bench_write_minichat(Id + 1, if Id rem 500 =:= 0 -> [{Id, T} | Temps]; > > true -> Temps end). > > > > > > /Greg Burri > > > > _______________________________________________ > > erlang-questions mailing list > > erlang-questions > > http://www.erlang.org/mailman/listinfo/erlang-questions > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081003/954cccb9/attachment.html From ulf Fri Oct 3 08:30:26 2008 From: ulf (Ulf Wiger) Date: Fri, 3 Oct 2008 08:30:26 +0200 Subject: [erlang-questions] The Erlang Rationale In-Reply-To: <3A1A577F-46AF-4923-A327-3B36238CB116@cs.otago.ac.nz> References: <3dbc6d1c0809291502m3ad2147djfdc652a8e5c7a157@mail.gmail.com> <3dbc6d1c0809300519kd46dbadsdfb670f71865b5@mail.gmail.com> <48E21D43.1040509@gmail.com> <4ac8254d0809300609m7c72c6b2je9774a70c629acf8@mail.gmail.com> <3dbc6d1c0809300630q35221794jf0922f370de6dd04@mail.gmail.com> <6c2563b20810010649xdb362dcyefc9e361608b33f7@mail.gmail.com> <48E4770E.7040303@bigpond.net.au> <3A1A577F-46AF-4923-A327-3B36238CB116@cs.otago.ac.nz> Message-ID: <8209f740810022330k1f0c8665h952f86ef8dfa533@mail.gmail.com> 2008/10/3 Richard O'Keefe : > > I then mentioned ?HERE as a possible idea that would leave the > source code with a visible mention of "at this point I pass my > source location" -- hence would be more tokens to type than > using a macro -- but in a much shorter and potentially richer > form than ?MODULE, ?LINE. > > Given my history of writing EEPS, readers were expected to see this > as a pre-pre-EEP for ?HERE. Today I've mailed out patches to add a > prototype version of ?HERE that gives you {?MODULE,?LINE,undefined} > with undefined as a place-holder for a future {function,arity}. I've been using ?HERE quite often in my code. It may seem unintuitive, but it works, since macros are simply a syntactic expansion: -module(here). -compile(export_all). -define(HERE, {?MODULE, ?LINE, undefined}). f() -> {?HERE, ?HERE}. $ erl Eshell V5.6.4 (abort with ^G) 1> here:f(). {{here,9,undefined},{here,10,undefined}} 2> So no need to patch epp before one can start using it. It's possible to add to the macro a way to find out the current module and arity as well. In a previous thread: http://groups.google.com/group/erlang-questions/browse_thread/thread/ee2929a3c67375b8 -define(FUNCTION,element(2,process_info(self(),current_function))). Then we could make our HERE definition: -define(HERE, {?MODULE, ?LINE, ?FUNCTION}). BR, Ulf W From ulf Fri Oct 3 08:34:43 2008 From: ulf (Ulf Wiger) Date: Fri, 3 Oct 2008 08:34:43 +0200 Subject: [erlang-questions] Will mnesia transaction abort when the process who start it exits? In-Reply-To: References: Message-ID: <8209f740810022334v254f9efqbbf0f78f79ac74c6@mail.gmail.com> 2008/10/3 devdoer bird : > HI: > > When the process start a mnesia transaction exits, will the transaction > abort? Yes. > If the mnesia database operation is NOT in a transaction, That would be a dirty operation. > will the mnesia operation abort when the start process exit? No. Dirty is dirty. BR, Ulf W From erlang-questions_efine Fri Oct 3 09:30:39 2008 From: erlang-questions_efine (Edwin Fine) Date: Fri, 3 Oct 2008 03:30:39 -0400 Subject: [erlang-questions] The Erlang Rationale In-Reply-To: <6c2563b20810030028h35e63af0m78e74d83b2081739@mail.gmail.com> References: <3dbc6d1c0809291502m3ad2147djfdc652a8e5c7a157@mail.gmail.com> <4ac8254d0809300609m7c72c6b2je9774a70c629acf8@mail.gmail.com> <3dbc6d1c0809300630q35221794jf0922f370de6dd04@mail.gmail.com> <6c2563b20810010649xdb362dcyefc9e361608b33f7@mail.gmail.com> <48E4770E.7040303@bigpond.net.au> <3A1A577F-46AF-4923-A327-3B36238CB116@cs.otago.ac.nz> <8209f740810022330k1f0c8665h952f86ef8dfa533@mail.gmail.com> <6c2563b20810030028h35e63af0m78e74d83b2081739@mail.gmail.com> Message-ID: <6c2563b20810030030t23a4e8b3s61191c8ecbf7e0ed@mail.gmail.com> Apropos of all this macro and inline stuff, I tried Richard's suggestion for inlining but immediately hit an annoyance. in.hrl: -compile({inline, [{flog,3}]}). flog(L, F, A) -> case iutil_log:ok_to_log(info) of true -> iutil_log:log_info(?MODULE, L, F, A); false -> ok end. logtest.erl: -module(logtest). -include("in.hrl"). -export([go/0]). go() -> flog(?LINE, "Just logged using ~p's scheme~n", ["Richard O'Keefe"]). $ efine:/tmp$ erlc logtest.erl ./logtest.erl:3: attribute 'export' after function definitions ./in.hrl:3: Warning: function flog/3 is unused ./logtest.erl:5: Warning: function go/0 is unused Now to use this scheme, I have to ensure I put the -include AFTER all export statements. Seems annoying. Is there another way? E. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081003/e5297c16/attachment.html From devdoer2 Fri Oct 3 09:45:17 2008 From: devdoer2 (devdoer bird) Date: Fri, 3 Oct 2008 15:45:17 +0800 Subject: [erlang-questions] Will mnesia transaction abort when the process who start it exits? In-Reply-To: <8209f740810022334v254f9efqbbf0f78f79ac74c6@mail.gmail.com> References: <8209f740810022334v254f9efqbbf0f78f79ac74c6@mail.gmail.com> Message-ID: Thanks. 2008/10/3 Ulf Wiger > 2008/10/3 devdoer bird : > > HI: > > > > When the process start a mnesia transaction exits, will the transaction > > abort? > > Yes. > > > > If the mnesia database operation is NOT in a transaction, > > That would be a dirty operation. > > > > will the mnesia operation abort when the start process exit? > > No. Dirty is dirty. > > BR, > Ulf W > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081003/18fdba5a/attachment.html From koops.j Fri Oct 3 10:45:12 2008 From: koops.j (Jeroen Koops) Date: Fri, 3 Oct 2008 10:45:12 +0200 Subject: [erlang-questions] Can I suppress the error-report when stopping a gen_server? Message-ID: <331a9abb0810030145g167fe3a7gf6e4b792e1ebce30@mail.gmail.com> Hi, When a gen_server stops by returning {stop, Reason, State} from handle_cast or handle_call, an error report is logged to the shell: =ERROR REPORT==== 3-Oct-2008::10:39:45 === ** Generic server test_server terminating ** Last message in was {'$gen_cast',stop} ** When Server state == 37 ** Reason for termination == ** "Stop requested" ** exited: "Stop requested" ** Is there any way to suppress this? Thanks, Jeroen Koops -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081003/7ad8dd91/attachment.html From ulf.wiger Fri Oct 3 10:47:43 2008 From: ulf.wiger (Ulf Wiger (TN/EAB)) Date: Fri, 03 Oct 2008 10:47:43 +0200 Subject: [erlang-questions] The Erlang Rationale In-Reply-To: <6c2563b20810030030t23a4e8b3s61191c8ecbf7e0ed@mail.gmail.com> References: <3dbc6d1c0809291502m3ad2147djfdc652a8e5c7a157@mail.gmail.com> <4ac8254d0809300609m7c72c6b2je9774a70c629acf8@mail.gmail.com> <3dbc6d1c0809300630q35221794jf0922f370de6dd04@mail.gmail.com> <6c2563b20810010649xdb362dcyefc9e361608b33f7@mail.gmail.com> <48E4770E.7040303@bigpond.net.au> <3A1A577F-46AF-4923-A327-3B36238CB116@cs.otago.ac.nz> <8209f740810022330k1f0c8665h952f86ef8dfa533@mail.gmail.com> <6c2563b20810030028h35e63af0m78e74d83b2081739@mail.gmail.com> <6c2563b20810030030t23a4e8b3s61191c8ecbf7e0ed@mail.gmail.com> Message-ID: <48E5DC2F.1010304@ericsson.com> Edwin Fine skrev: > > Now to use this scheme, I have to ensure I put the -include AFTER all > export statements. Seems annoying. Is there another way? I don't know, but I always do it in that order anyway: 1. export declarations 2. import declarations 3. includes 4. records and defines BR, Ulf W From ulf Fri Oct 3 11:00:28 2008 From: ulf (Ulf Wiger) Date: Fri, 3 Oct 2008 11:00:28 +0200 Subject: [erlang-questions] Can I suppress the error-report when stopping a gen_server? In-Reply-To: <331a9abb0810030145g167fe3a7gf6e4b792e1ebce30@mail.gmail.com> References: <331a9abb0810030145g167fe3a7gf6e4b792e1ebce30@mail.gmail.com> Message-ID: <8209f740810030200i76939799oa1261dab1b9c2b3e@mail.gmail.com> Use {stop, normal, State} instead. BR, Ulf W 2008/10/3 Jeroen Koops : > Hi, > > When a gen_server stops by returning {stop, Reason, State} from handle_cast > or handle_call, an error report is logged to the shell: > > =ERROR REPORT==== 3-Oct-2008::10:39:45 === > ** Generic server test_server terminating > ** Last message in was {'$gen_cast',stop} > ** When Server state == 37 > ** Reason for termination == > ** "Stop requested" > ** exited: "Stop requested" ** > > Is there any way to suppress this? > > Thanks, > > Jeroen Koops > > > > > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From koops.j Fri Oct 3 11:07:31 2008 From: koops.j (Jeroen Koops) Date: Fri, 3 Oct 2008 11:07:31 +0200 Subject: [erlang-questions] Can I suppress the error-report when stopping a gen_server? In-Reply-To: <8209f740810030200i76939799oa1261dab1b9c2b3e@mail.gmail.com> References: <331a9abb0810030145g167fe3a7gf6e4b792e1ebce30@mail.gmail.com> <8209f740810030200i76939799oa1261dab1b9c2b3e@mail.gmail.com> Message-ID: <331a9abb0810030207l41fbca21x6d5dc8235af197b@mail.gmail.com> Great, thanks. On Fri, Oct 3, 2008 at 11:00 AM, Ulf Wiger wrote: > Use {stop, normal, State} instead. > > BR, > Ulf W > > 2008/10/3 Jeroen Koops : > > Hi, > > > > When a gen_server stops by returning {stop, Reason, State} from > handle_cast > > or handle_call, an error report is logged to the shell: > > > > =ERROR REPORT==== 3-Oct-2008::10:39:45 === > > ** Generic server test_server terminating > > ** Last message in was {'$gen_cast',stop} > > ** When Server state == 37 > > ** Reason for termination == > > ** "Stop requested" > > ** exited: "Stop requested" ** > > > > Is there any way to suppress this? > > > > Thanks, > > > > Jeroen Koops > > > > > > > > > > > > > > _______________________________________________ > > erlang-questions mailing list > > erlang-questions > > http://www.erlang.org/mailman/listinfo/erlang-questions > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081003/93ee928a/attachment.html From dgud Fri Oct 3 12:08:35 2008 From: dgud (Dan Gudmundsson) Date: Fri, 03 Oct 2008 12:08:35 +0200 Subject: [erlang-questions] Request to add md4 to crypto module In-Reply-To: <200810030329.09362.alexander.uvarov@gmail.com> References: <200810030329.09362.alexander.uvarov@gmail.com> Message-ID: <48E5EF23.3050708@erix.ericsson.se> You don't have to write (in my mind) an EEP for adding things in a library, EEP is for language changes or other major erlang changes. Send a patch to erlang-patches, and if we thinks it's ok and have time we will add it. /Dan "Currently adding things to crypto" Alexander wrote: > On Thursday 02 October 2008 23:28:29 Jim McCoy wrote: >> After poking around a bit in the OTP sources it seems that it would be >> pretty trivial to add md4 to the crypto module. I will be testing a >> few patches later this week, but before I throw together a real EEP I >> was hoping that this might be a simple-enough change that the OTP team >> might consider adding it without the need for the formal process. > > +1 for enhancement, also it would be useful to have DES in ECB mode too > (trivial). If someone interested, there is my implementation based on erlang > crypto driver (md4, des in ecb mode - used by mschapv2) > http://pastie.org/283903 > > Also, why not make MD2 and finish dance with MD* crypto in erlang? :) > >> As for the rationale: some applications (dhts, etc) need a large, fast >> hash that has a good uniqueness distribution but are not worried about >> the security implications of selecting an algorithm that is >> cryptographically weak. The md4 hash is about 50% faster than md5, >> which is a real win when you are hashing thousands of items. Since >> there are already "questionable" algorithms included in the crypto >> module (e.g. md5 and rc2) it seems that a warning in the docs that >> this algorithm should not be used for security-sensitive tasks would >> be sufficient notice to developers. >> >> Any thoughts or objections? >> >> jim >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions >> http://www.erlang.org/mailman/listinfo/erlang-questions > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From joelr1 Fri Oct 3 12:17:59 2008 From: joelr1 (Joel Reymont) Date: Fri, 3 Oct 2008 11:17:59 +0100 Subject: [erlang-questions] Request to add md4 to crypto module In-Reply-To: <48E5EF23.3050708@erix.ericsson.se> References: <200810030329.09362.alexander.uvarov@gmail.com> <48E5EF23.3050708@erix.ericsson.se> Message-ID: Is there a reason why RC4 is present but not RC5? openssl supports both. Is this a patch issue? Thanks, Joel On Oct 3, 2008, at 11:08 AM, Dan Gudmundsson wrote: > You don't have to write (in my mind) an EEP for adding things in a > library, > EEP is for language changes or other major erlang changes. > > Send a patch to erlang-patches, and if we thinks it's ok and have > time we will add it. -- wagerlabs.com From tuncer.ayaz Fri Oct 3 12:34:12 2008 From: tuncer.ayaz (Tuncer Ayaz) Date: Fri, 3 Oct 2008 12:34:12 +0200 Subject: [erlang-questions] Request to add md4 to crypto module In-Reply-To: References: <200810030329.09362.alexander.uvarov@gmail.com> <48E5EF23.3050708@erix.ericsson.se> Message-ID: <4ac8254d0810030334u26e9ee50y5ffe2953626704eb@mail.gmail.com> On Fri, Oct 3, 2008 at 12:17 PM, Joel Reymont wrote: > Is there a reason why RC4 is present but not RC5? Possibly caused by the patent expiring in 2018? > openssl supports both. > > Is this a patch issue? > > Thanks, Joel > > On Oct 3, 2008, at 11:08 AM, Dan Gudmundsson wrote: > >> You don't have to write (in my mind) an EEP for adding things in a >> library, >> EEP is for language changes or other major erlang changes. >> >> Send a patch to erlang-patches, and if we thinks it's ok and have >> time we will add it. > > -- > wagerlabs.com > > > > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From vladdu55 Fri Oct 3 13:13:04 2008 From: vladdu55 (Vlad Dumitrescu) Date: Fri, 3 Oct 2008 13:13:04 +0200 Subject: [erlang-questions] extending the scanner and parser Message-ID: <95be1d3b0810030413p52bc5b58uf22c6790d64f9f35@mail.gmail.com> Hi, Tools that process Erlang source code need more detailed information about the lexical tokens than those provided by the scanner in the standard distribution. For example, ErlIDE needs the character offset in the file and also the textual representation of the token. It also adds as an optimization the length of the textual token. Wrangler uses column information. These tools also need to be able to reconstruct the source code from the token list. For this to be possible, it must be possible to ask the scanner to return even whitespace and comments. It must also be possible to know the exact textual representation of the token, for example an integer valued 42 may have been written as "42" or as "16#2A" in the source file. In a similar way, the parse tree may need to know for each construct where it starts and where it ends in the source, so it needs to keep track of the underlying tokens. The way these tools get the extra information is by making a copy of erl_scan and erl_parse and modifying them to suit their purposes. This is a big maintenance headache and it limits interoperability between these tools, but currently the only way to solve the problem. Therefore I would like to suggest to extend the standard scanner and parser to support such extra information. If there will be a consensus that this is a Good Thing, I will happily provide a reference implementation in cooperation with any interested parties. If there is not enough general interest, I would still like to call out to all those who develope source handling tools and see if we could create a common library to share. best regards, Vlad From joelr1 Fri Oct 3 15:29:03 2008 From: joelr1 (Joel Reymont) Date: Fri, 3 Oct 2008 14:29:03 +0100 Subject: [erlang-questions] dialyzer: the pattern ... can never match the type 100 Message-ID: Any suggestions on how to fix this? pot.erl:28: The pattern Pot = {'side_pot', _, _} can never match the type 100 Thanks, Joel --- -record(side_pot, { members, all_in }). new_side_pot(AllInAmt, Members) -> #side_pot{ all_in = AllInAmt, members = Members }. %% vvv This is what it's complaining about new_side_pot(Pot = #side_pot{}) -> new_side_pot(Pot#side_pot.all_in, Pot#side_pot.members); new_side_pot(AllInAmt) when is_number(AllInAmt) -> new_side_pot(AllInAmt, gb_trees:empty()). new_side_pot() -> new_side_pot(0, gb_trees:empty()). -- wagerlabs.com From nick Fri Oct 3 15:52:51 2008 From: nick (Niclas Eklund) Date: Fri, 3 Oct 2008 15:52:51 +0200 (CEST) Subject: [erlang-questions] dialyzer: the pattern ... can never match the type 100 In-Reply-To: References: Message-ID: Hello! Change from: new_side_pot(Pot = #side_pot{}) -> to: new_side_pot(#side_pot{} = Pot) -> /Niclas @ Erlang/OTP On Fri, 3 Oct 2008, Joel Reymont wrote: > Any suggestions on how to fix this? > > pot.erl:28: The pattern Pot = {'side_pot', _, _} can never match the > type 100 > > Thanks, Joel > > --- > > -record(side_pot, { > members, > all_in > }). > > new_side_pot(AllInAmt, Members) -> > #side_pot{ > all_in = AllInAmt, > members = Members > }. > > %% vvv This is what it's complaining about > new_side_pot(Pot = #side_pot{}) -> > new_side_pot(Pot#side_pot.all_in, Pot#side_pot.members); > > new_side_pot(AllInAmt) > when is_number(AllInAmt) -> > new_side_pot(AllInAmt, gb_trees:empty()). > > new_side_pot() -> > new_side_pot(0, gb_trees:empty()). > > > -- > wagerlabs.com > > > > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From joelr1 Fri Oct 3 15:53:34 2008 From: joelr1 (Joel Reymont) Date: Fri, 3 Oct 2008 14:53:34 +0100 Subject: [erlang-questions] dialyzer: the pattern ... can never match the type 100 In-Reply-To: References: Message-ID: <7FF0B3A7-A9BA-442F-B769-28C17B3415C1@gmail.com> On Oct 3, 2008, at 2:52 PM, Niclas Eklund wrote: > new_side_pot(#side_pot{} = Pot) -> > Thank you Niclas! What is the reason for doing it this way, though? I have ...(X = #foo{}) all over the code but this is the only place where Dialyzer is complaining about it. -- wagerlabs.com From lestat Fri Oct 3 16:04:54 2008 From: lestat (Tamas Nagy) Date: Fri, 3 Oct 2008 15:04:54 +0100 Subject: [erlang-questions] extending the scanner and parser In-Reply-To: <95be1d3b0810030413p52bc5b58uf22c6790d64f9f35@mail.gmail.com> References: <95be1d3b0810030413p52bc5b58uf22c6790d64f9f35@mail.gmail.com> Message-ID: <8DDF50EC-D01D-4DC3-90EF-7E51185C6160@elte.hu> Hi Vlad! Check out RefactorErl and contact the developers if you need something which is not available. I'm pretty sure they can help. It provides all the functionality which is mentioned in your e-mail. (These are all needed for refactoring as well to be able to retain the original layout). Furthermore it has an API to retrieve this information. So you do not have to hack it to get the data needed. :) The website: http://plc.inf.elte.hu/erlang/ Regards, Tamas On 3 Oct 2008, at 12:13, Vlad Dumitrescu wrote: > Hi, > > Tools that process Erlang source code need more detailed information > about the lexical tokens than those provided by the scanner in the > standard distribution. For example, ErlIDE needs the character offset > in the file and also the textual representation of the token. It also > adds as an optimization the length of the textual token. Wrangler > uses column information. > > These tools also need to be able to reconstruct the source code from > the token list. For this to be possible, it must be possible to ask > the scanner to return even whitespace and comments. It must also be > possible to know the exact textual representation of the token, for > example an integer valued 42 may have been written as "42" or as > "16#2A" in the source file. > > In a similar way, the parse tree may need to know for each construct > where it starts and where it ends in the source, so it needs to keep > track of the underlying tokens. > > The way these tools get the extra information is by making a copy of > erl_scan and erl_parse and modifying them to suit their purposes. > This is a big maintenance headache and it limits interoperability > between these tools, but currently the only way to solve the problem. > > Therefore I would like to suggest to extend the standard scanner and > parser to support such extra information. If there will be a consensus > that this is a Good Thing, I will happily provide a reference > implementation in cooperation with any interested parties. > > If there is not enough general interest, I would still like to call > out to all those who develope source handling tools and see if we > could create a common library to share. > > best regards, > Vlad > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions From erlang-questions_efine Fri Oct 3 17:01:16 2008 From: erlang-questions_efine (Edwin Fine) Date: Fri, 3 Oct 2008 11:01:16 -0400 Subject: [erlang-questions] The Erlang Rationale In-Reply-To: <48E5DC2F.1010304@ericsson.com> References: <3dbc6d1c0809291502m3ad2147djfdc652a8e5c7a157@mail.gmail.com> <6c2563b20810010649xdb362dcyefc9e361608b33f7@mail.gmail.com> <48E4770E.7040303@bigpond.net.au> <3A1A577F-46AF-4923-A327-3B36238CB116@cs.otago.ac.nz> <8209f740810022330k1f0c8665h952f86ef8dfa533@mail.gmail.com> <6c2563b20810030028h35e63af0m78e74d83b2081739@mail.gmail.com> <6c2563b20810030030t23a4e8b3s61191c8ecbf7e0ed@mail.gmail.com> <48E5DC2F.1010304@ericsson.com> Message-ID: <6c2563b20810030801g27c1c45bg8910617c0859783a@mail.gmail.com> Thank you. On Fri, Oct 3, 2008 at 4:47 AM, Ulf Wiger (TN/EAB) wrote: > Edwin Fine skrev: > >> >> Now to use this scheme, I have to ensure I put the -include AFTER all >> export statements. Seems annoying. Is there another way? >> > > I don't know, but I always do it in that order anyway: > > 1. export declarations > 2. import declarations > 3. includes > 4. records and defines > > BR, > Ulf W > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081003/8eb72fe2/attachment.html From H.Li Fri Oct 3 17:15:27 2008 From: H.Li (H.Li) Date: Fri, 3 Oct 2008 16:15:27 +0100 Subject: [erlang-questions] extending the scanner and parser In-Reply-To: <95be1d3b0810030413p52bc5b58uf22c6790d64f9f35@mail.gmail.com> References: <95be1d3b0810030413p52bc5b58uf22c6790d64f9f35@mail.gmail.com> Message-ID: <20081003151527.GA28655@myrtle.kent.ac.uk> > > The way these tools get the extra information is by making a copy of > erl_scan and erl_parse and modifying them to suit their purposes. > This is a big maintenance headache and it limits interoperability > between these tools, but currently the only way to solve the problem. That's exactly what Wrangler does. It would be really great if the standard scanner could be extended to support extra information. Regards, Huiqing From kenneth.lundin Fri Oct 3 18:18:04 2008 From: kenneth.lundin (Kenneth Lundin) Date: Fri, 3 Oct 2008 18:18:04 +0200 Subject: [erlang-questions] extending the scanner and parser In-Reply-To: <20081003151527.GA28655@myrtle.kent.ac.uk> References: <95be1d3b0810030413p52bc5b58uf22c6790d64f9f35@mail.gmail.com> <20081003151527.GA28655@myrtle.kent.ac.uk> Message-ID: It is in our plans to have that support in our standard scanner in some way. Can not promise when but hopefully next year some time. /Kenneth Erlang/OTP tema , Ericsson On Fri, Oct 3, 2008 at 5:15 PM, H.Li wrote: > >> >> The way these tools get the extra information is by making a copy of >> erl_scan and erl_parse and modifying them to suit their purposes. >> This is a big maintenance headache and it limits interoperability >> between these tools, but currently the only way to solve the problem. > > That's exactly what Wrangler does. It would be really great if the standard > scanner could be extended to support extra information. > > Regards, > Huiqing > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From dawsdesign Fri Oct 3 19:05:45 2008 From: dawsdesign (Matt Williamson) Date: Fri, 3 Oct 2008 13:05:45 -0400 Subject: [erlang-questions] OTP.NET Error Message-ID: I'm trying out a simple OTP.NET test and it works great for the first call, but any subsequent calls result in the following exception: System.IO.IOException was unhandled Message="Peer replied with status 'alive' instead of 'ok'" Source="Otp" StackTrace: at Otp.AbstractConnection.recvStatus() in C:\Documents and Settings\Administrator\Desktop\jungerl\lib\otp.net\Otp\AbstractConnection.cs:line 1455 at Otp.AbstractConnection.doConnect(Int32 port) in C:\Documents and Settings\Administrator\Desktop\jungerl\lib\otp.net\Otp\AbstractConnection.cs:line 1018 at Otp.AbstractConnection..ctor(OtpLocalNode self, OtpPeer other) in C:\Documents and Settings\Administrator\Desktop\jungerl\lib\otp.net\Otp\AbstractConnection.cs:line 226 at Otp.OtpConnection..ctor(OtpSelf self, OtpPeer other) in C:\Documents and Settings\Administrator\Desktop\jungerl\lib\otp.net\Otp\OtpConnection.cs:line 84 at Otp.OtpPeer.connect(OtpSelf self) in C:\Documents and Settings\Administrator\Desktop\jungerl\lib\otp.net\Otp\OtpPeer.cs:line 67 at ErlTestClient.Form1.button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\Administrator\My Documents\Projects\ErlTestClient\ErlTestClient\Form1.cs:line 25 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at ErlTestClient.Program.Main() in C:\Documents and Settings\Administrator\My Documents\Projects\ErlTestClient\ErlTestClient\Program.cs:line 17 at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() You can view my source at http://paste.lisp.org/display/67861 and http://paste.lisp.org/display/67862 Erlang is v5.6.3 on windows and I'm running VS2005. Please help :) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081003/4c4bd041/attachment.html From wglozer Fri Oct 3 19:20:00 2008 From: wglozer (Will) Date: Fri, 3 Oct 2008 10:20:00 -0700 Subject: [erlang-questions] [bug] beam_asm failure on invalid binary match Message-ID: Hello, I mistakenly set the size specifier in a binary match to zero and it caused beam_asm to crash. This is Erlang/OTP R12B-4. Test case: test3() -> <> = <<2, 0, $h, $i, 0>>. Result: crash reason: {function_clause,[{beam_dict,old_string,[[],[]]}, {beam_dict,string,2}, {beam_asm,encode_arg,2}, {beam_asm,encode_op_1,3}, {beam_asm,assemble_function,3}, {beam_asm,assemble_1,4}, {beam_asm,assemble,4}, {beam_asm,module,4}]} Thanks, Will -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081003/66c5400b/attachment.html From vladdu55 Fri Oct 3 20:26:49 2008 From: vladdu55 (Vlad Dumitrescu) Date: Fri, 3 Oct 2008 20:26:49 +0200 Subject: [erlang-questions] extending the scanner and parser In-Reply-To: References: <95be1d3b0810030413p52bc5b58uf22c6790d64f9f35@mail.gmail.com> <20081003151527.GA28655@myrtle.kent.ac.uk> Message-ID: <95be1d3b0810031126t5fb7b8b9x48bb75c3895a330e@mail.gmail.com> On Fri, Oct 3, 2008 at 18:18, Kenneth Lundin wrote: > It is in our plans to have that support in our standard scanner in some way. > Can not promise when but hopefully next year some time. That's wonderful to know! I suppose that it wouldn't hurt if we (the tool makers) would start right away to tinker with it so that when you're ready you will have something almost ready to work with, would it? best regards, Vlad From sean.d.payne Fri Oct 3 20:52:09 2008 From: sean.d.payne (Sean Payne) Date: Fri, 3 Oct 2008 11:52:09 -0700 Subject: [erlang-questions] Erlang timer program - feedback please Message-ID: <4d775bd70810031152g57c4f217vd181a8b3db3248db@mail.gmail.com> I am hoping someone with more Erlang experience than me could give me some feedback on the timer code below. I am using erlang:start_timer and tail recursion with a paused state and a running state to create a little simulation * world:init(). inits the sim * world:run(). starts the updates (right now updates just print out "updating") * world:pause(). pauses the updates * world:destroy(). shuts it down So my questions are: 1) Is there a better way (timer wise) to do this. I suspect that the way I am using the timer that my update_now will not be called at the right frequency because of the delay between when the event fires and when the next event is scheduled. 2) Is there a better way Erlang wise to do something like this. I am new to Erlang, so I am curious if this is the approach that someone with more experience would take. Is this how you would write this????? 3) Are there any bugs or leaks? ie am I using Tail recursion correctly? (every time I pause or unpause the program, am I going deeper into the stack?) Thanks, Sean ========================================= -module(world). %% External interfaces %% world:init sets up the world (into the paused state) %% world:run starts the timers and updates every UPDATE_INTERVAL %% world:stop pauses the world %% world:destroy destroys the world -export([init/0]). -export([run/0]). -export([stop/0]). -export([destroy/0]). %% internal functions but must be exported to receive events from erlang:start_timer -export([handle_events_while_stopped/0]). -export([handle_events_while_running/0]). -define(UPDATE_INTERVAL,1000). handle_events_while_stopped() -> receive finished-> io:format("world is finished~n", []); run-> io:format("world is running~n", []), erlang:start_timer(?UPDATE_INTERVAL, self(), update_now), handle_events_while_running() end. handle_events_while_running() -> receive finished-> io:format("world is finished~n", []); stop-> io:format("world is stopping~n", []), handle_events_while_stopped(); {timeout, _ , update_now} -> io:format("updating~n", []), erlang:start_timer(?UPDATE_INTERVAL, self(), update_now), handle_events_while_running() end. init() -> register(world, spawn(world, handle_events_while_stopped,[])). run()-> world ! run. stop()-> world ! stop. destroy()-> world ! finished. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081003/e6edc5e5/attachment.html From erlang-questions_efine Fri Oct 3 21:02:15 2008 From: erlang-questions_efine (Edwin Fine) Date: Fri, 3 Oct 2008 15:02:15 -0400 Subject: [erlang-questions] Unused inline functions compiler warning Message-ID: <6c2563b20810031202u6dcf65bdqa88d2c09c193376b@mail.gmail.com> I'm trying to convert my code base from using macros for logging to using inline functions, as advocated by Richard O'Keefe. In an include (.hrl) file, I have inline function definitions like -compile({inline, [{log_info,3}, ...]). log_info(Line, Fmt, Args) -> ok = . %% Some code ... However, if I include this file and don't use all of the inline functions, I get a compiler warning for each unused function: warning:function ilog_error/3 is unused ... and more Does this imply that every inline function in a .hrl file will be inserted into every single .erl file that includes it, even if it is unused? If not, then why have a compiler warning? Is there any way to overcome this without reverting back to using macros? Can I get rid of just those warnings? Is there a way to suppress warnings for individual functions, like a -compile({suppress, [{wunused, [{log_info,3},{log_dbg,3}]}]})? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081003/2f7a1b9d/attachment-0001.html From kostis Fri Oct 3 21:42:31 2008 From: kostis (Kostis Sagonas) Date: Fri, 03 Oct 2008 22:42:31 +0300 Subject: [erlang-questions] dialyzer: the pattern ... can never match the type 100 In-Reply-To: References: Message-ID: <48E675A7.8090900@cs.ntua.gr> Joel Reymont wrote: > Any suggestions on how to fix this? > > pot.erl:28: The pattern Pot = {'side_pot', _, _} can never match the > type 100 How more explicit can the warning be? It says that you have a function (I am willing to bet that it is not exported) and the only call to it is with the integer 100. The first clause below is clearly dead code -- the pattern will never match 100. %% vvv This is what it's complaining about new_side_pot(Pot = #side_pot{}) -> new_side_pot(Pot#side_pot.all_in, Pot#side_pot.members); new_side_pot(AllInAmt) when is_number(AllInAmt) -> new_side_pot(AllInAmt, gb_trees:empty()). The solution to this one is to comment the clause out or simply remove it. It's simply not needed in your module. Kostis PS. What Niclas wrote as a "solution" is very misleading. AFAIK there is no difference between Pot = #side_pot{} and #side_pot{} = Pot in a clause head. From dloutrein.lists Fri Oct 3 23:40:43 2008 From: dloutrein.lists (denis) Date: Fri, 3 Oct 2008 17:40:43 -0400 Subject: [erlang-questions] xmerl_xpath and namespaces Message-ID: <48e6915d.050cc00a.5255.ffffba16@mx.google.com> Hello, I'm having some problem using xmerl_xpath on a document having namespaces. I'm not sure I fully understand how all of this work and the problem should not come from xmerl_xpath, but from my misunderstanding of xml, namespace, xpath. It seems that with xpath, it's mandatory to give the namespace. For instance, in a document like this: If I want to get all "element" attributes, I need to do a query like xmerl_xpath:string("//xs:simpleType", X) Is there a way to not having to give the namespace in the query ?? Another related question is the usage of {namespace, .} option in the query. What is it's usage ? A tried something like this xmerl_xpath:string("//simpleType", X, [{namespace, X#xmlElement.namespace}]). Hoping for a miracle. Of course, no miracle :-) I don't understand what do this option. My problem is that I get different schema "element"s, which are in two different namespaces. I can't see how to retrieve them using xpath. One namespace is declared in the root element, so I can get it's definition and add the namespace manually when building the query, but in the case above, the namespace is defined in the schema node itself, so I can't get it. If anybody can give me some highlight or pointers, this would help me a lot ! :-) Thanks Denis -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081003/590b895c/attachment.html From wglozer Fri Oct 3 23:49:57 2008 From: wglozer (Will) Date: Fri, 3 Oct 2008 14:49:57 -0700 Subject: [erlang-questions] Request to add md4 to crypto module In-Reply-To: <48E5EF23.3050708@erix.ericsson.se> References: <200810030329.09362.alexander.uvarov@gmail.com> <48E5EF23.3050708@erix.ericsson.se> Message-ID: Hi Dan, Glad to hear you're in the midst of work on crypto! I submitted patches a long time ago to add MD5 and SHA1 signing and verification with RSA keys. I'd love to see this included in crypto. http://article.gmane.org/gmane.comp.lang.erlang.patches/151 Thanks, Will On Fri, Oct 3, 2008 at 3:08 AM, Dan Gudmundsson wrote: > You don't have to write (in my mind) an EEP for adding things in a library, > EEP is for language changes or other major erlang changes. > > Send a patch to erlang-patches, and if we thinks it's ok and have time we > will add it. > > /Dan "Currently adding things to crypto" > > Alexander wrote: > > On Thursday 02 October 2008 23:28:29 Jim McCoy wrote: > >> After poking around a bit in the OTP sources it seems that it would be > >> pretty trivial to add md4 to the crypto module. I will be testing a > >> few patches later this week, but before I throw together a real EEP I > >> was hoping that this might be a simple-enough change that the OTP team > >> might consider adding it without the need for the formal process. > > > > +1 for enhancement, also it would be useful to have DES in ECB mode too > > (trivial). If someone interested, there is my implementation based on > erlang > > crypto driver (md4, des in ecb mode - used by mschapv2) > > http://pastie.org/283903 > > > > Also, why not make MD2 and finish dance with MD* crypto in erlang? :) > > > >> As for the rationale: some applications (dhts, etc) need a large, fast > >> hash that has a good uniqueness distribution but are not worried about > >> the security implications of selecting an algorithm that is > >> cryptographically weak. The md4 hash is about 50% faster than md5, > >> which is a real win when you are hashing thousands of items. Since > >> there are already "questionable" algorithms included in the crypto > >> module (e.g. md5 and rc2) it seems that a warning in the docs that > >> this algorithm should not be used for security-sensitive tasks would > >> be sufficient notice to developers. > >> > >> Any thoughts or objections? > >> > >> jim > >> _______________________________________________ > >> erlang-questions mailing list > >> erlang-questions > >> http://www.erlang.org/mailman/listinfo/erlang-questions > > > > _______________________________________________ > > erlang-questions mailing list > > erlang-questions > > http://www.erlang.org/mailman/listinfo/erlang-questions > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081003/17bc3e4f/attachment.html From erlang-questions_efine Sat Oct 4 00:00:46 2008 From: erlang-questions_efine (Edwin Fine) Date: Fri, 3 Oct 2008 18:00:46 -0400 Subject: [erlang-questions] Unused inline functions compiler warning - solved Message-ID: <6c2563b20810031500k7681b0a1rce94ff0807b060d0@mail.gmail.com> Please ignore this. I didn't RTFM properly so I missed the {nowarn_unused_function, FAs} in the compile module documentation. For the record, *unused inline functions are inserted into the module if compile([export_all]) is defined*, but not if functions are exported individually. This is hinted at indirectly in the documentation about inline functions: "When a function is inlined, the original function may be kept as a separate function as well, because there might still be calls to it." On Fri, Oct 3, 2008 at 3:02 PM, Edwin Fine wrote: > I'm trying to convert my code base from using macros for logging to using > inline functions, as advocated by Richard O'Keefe. > > In an include (.hrl) file, I have inline function definitions like > > -compile({inline, [{log_info,3}, ...]). > > log_info(Line, Fmt, Args) -> > ok = . %% Some code > ... > > However, if I include this file and don't use all of the inline functions, > I get a compiler warning for each unused function: > > warning:function ilog_error/3 is unused > ... and more > > Does this imply that every inline function in a .hrl file will be inserted > into every single .erl file that includes it, even if it is unused? If not, > then why have a compiler warning? > > Is there any way to overcome this without reverting back to using macros? > > Can I get rid of just those warnings? Is there a way to suppress warnings > for individual functions, like a -compile({suppress, [{wunused, > [{log_info,3},{log_dbg,3}]}]})? > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081003/87861ce3/attachment.html From saleyn Sat Oct 4 04:38:24 2008 From: saleyn (Serge Aleynikov) Date: Fri, 03 Oct 2008 22:38:24 -0400 Subject: [erlang-questions] OTP.NET Error In-Reply-To: References: Message-ID: <48E6D720.1080404@gmail.com> I took a quick look at your code and see that you are doing this on every button click which is wrong: OtpSelf self = new OtpSelf("client", "abc123"); OtpPeer server = new OtpPeer("server"); OtpConnection connection = server.connect(self); Move that to form initialization function, and try again. I guess what's going on is that OtpAbstractNode doesn't implement proper destruction and freeing resources (the socket connection), and as a result on every button click you are trying to set up more than one connection with the Erlang server node, which is not allowed, so the server drops the second and following connection attempts. Serge Matt Williamson wrote: > I'm trying out a simple OTP.NET test and it works great for the first call, > but any subsequent calls result in the following exception: > System.IO.IOException was unhandled > Message="Peer replied with status 'alive' instead of 'ok'" > Source="Otp" > StackTrace: > at Otp.AbstractConnection.recvStatus() in C:\Documents and > Settings\Administrator\Desktop\jungerl\lib\otp.net\Otp\AbstractConnection.cs:line > 1455 > at Otp.AbstractConnection.doConnect(Int32 port) in C:\Documents and > Settings\Administrator\Desktop\jungerl\lib\otp.net\Otp\AbstractConnection.cs:line > 1018 > at Otp.AbstractConnection..ctor(OtpLocalNode self, OtpPeer other) in > C:\Documents and > Settings\Administrator\Desktop\jungerl\lib\otp.net\Otp\AbstractConnection.cs:line > 226 > at Otp.OtpConnection..ctor(OtpSelf self, OtpPeer other) in > C:\Documents and > Settings\Administrator\Desktop\jungerl\lib\otp.net\Otp\OtpConnection.cs:line > 84 > at Otp.OtpPeer.connect(OtpSelf self) in C:\Documents and > Settings\Administrator\Desktop\jungerl\lib\otp.net\Otp\OtpPeer.cs:line 67 > at ErlTestClient.Form1.button1_Click(Object sender, EventArgs e) in > C:\Documents and Settings\Administrator\My > Documents\Projects\ErlTestClient\ErlTestClient\Form1.cs:line 25 > at System.Windows.Forms.Control.OnClick(EventArgs e) > at System.Windows.Forms.Button.OnClick(EventArgs e) > at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) > at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons > button, Int32 clicks) > at System.Windows.Forms.Control.WndProc(Message& m) > at System.Windows.Forms.ButtonBase.WndProc(Message& m) > at System.Windows.Forms.Button.WndProc(Message& m) > at > System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) > at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& > m) > at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, > Int32 msg, IntPtr wparam, IntPtr lparam) > at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& > msg) > at > System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 > dwComponentID, Int32 reason, Int32 pvLoopData) > at > System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 > reason, ApplicationContext context) > at > System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, > ApplicationContext context) > at System.Windows.Forms.Application.Run(Form mainForm) > at ErlTestClient.Program.Main() in C:\Documents and > Settings\Administrator\My > Documents\Projects\ErlTestClient\ErlTestClient\Program.cs:line 17 > at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] > args) > at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence > assemblySecurity, String[] args) > at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() > at System.Threading.ThreadHelper.ThreadStart_Context(Object state) > at System.Threading.ExecutionContext.Run(ExecutionContext > executionContext, ContextCallback callback, Object state) > at System.Threading.ThreadHelper.ThreadStart() > > > You can view my source at http://paste.lisp.org/display/67861 and > http://paste.lisp.org/display/67862 > > Erlang is v5.6.3 on windows and I'm running VS2005. > > Please help :) > > > > ------------------------------------------------------------------------ > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions From saleyn Sat Oct 4 07:32:55 2008 From: saleyn (Serge Aleynikov) Date: Sat, 04 Oct 2008 01:32:55 -0400 Subject: [erlang-questions] jinterface (was: otp.net) In-Reply-To: <48E58445.6050806@gmail.com> References: <48E58445.6050806@gmail.com> Message-ID: <48E70007.1020004@gmail.com> I tried a similar test using jinterface to see if it's possible to monitor processes running on a Java node and ran into the same failure. Can anyone explain what's wrong? (server)10> {test, client} ! {self(), hello}. {<0.45.0>,hello} (server)11> f(), {Pid, _} = receive M -> M end. {<5979.1.0>,hello} (server)12> erlang:monitor(process, Pid). ** exception error: bad argument in function erlang:monitor/2 called as erlang:monitor(process,<5979.1.0>) The corresponding java node was implemented using code below: import com.ericsson.otp.erlang.*; public class test { public static void main (String args[]) { System.out.println ("Hello World!"); try { OtpSelf self = new OtpSelf("client", "abc123"); OtpPeer other = new OtpPeer("server"); OtpConnection connection = self.connect(other); connection.sendRPC("erlang","date",new OtpErlangList()); OtpErlangObject received = connection.receiveRPC(); System.out.println("erlang:date() -> " + received + "\n"); OtpErlangObject o; OtpErlangTuple msg; OtpErlangPid from; while (true) { try { o = connection.receive(); if (o instanceof OtpErlangTuple) { msg = (OtpErlangTuple)o; from = (OtpErlangPid)(msg.elementAt(0)); connection.send(from, new OtpErlangTuple( new OtpErlangObject[] { self.pid(), msg.elementAt(1) } ) ); } } catch (Exception e) { System.out.println("" + e); } } } catch (Exception e) { System.out.println("" + e); } } } Serge Aleynikov wrote: > While playing with the otp.net project for the past several days I ran > into one problem that I can't quite explain. I am starting a .NET node > (saleyn) and connecting to a regular Erlang node > (a), then send a Pid from .NET to Erlang and try to set up a > monitor. The monitor call fails with badarg: > > (a)2> register(test, self()). > true > (a)3> nodes(hidden). > [saleyn] > (a)4> f(M), M = receive M -> M end. > <5852.1.0> > (a)5> M ! {hello, self()}. > {hello,<0.50.0>} > (a)6> erlang:monitor(process, M). > ** exception error: bad argument > in function erlang:monitor/2 > called as erlang:monitor(process,<5852.1.0>) > (a)7> > > I am able to send messages back and forth between two nodes and verify > their delivery, but don't understand why the monitor call would fail. > Does anyone have a clue? > > Serge > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From joelr1 Sat Oct 4 11:32:49 2008 From: joelr1 (Joel Reymont) Date: Sat, 4 Oct 2008 10:32:49 +0100 Subject: [erlang-questions] dialyzer: the pattern ... can never match the type 100 In-Reply-To: <48E675A7.8090900@cs.ntua.gr> References: <48E675A7.8090900@cs.ntua.gr> Message-ID: On Oct 3, 2008, at 8:42 PM, Kostis Sagonas wrote: > It says that you have a function (I am willing to bet that it is not > exported) and the only call to it is with the integer 100. The > first clause below is clearly dead code -- the pattern will never > match 100. It's not evident that "the type 100" refers to the integer 100. Could the wording be changed perhaps? -- wagerlabs.com From vladdu55 Sat Oct 4 13:07:12 2008 From: vladdu55 (Vlad Dumitrescu) Date: Sat, 4 Oct 2008 13:07:12 +0200 Subject: [erlang-questions] jinterface (was: otp.net) In-Reply-To: <48E70007.1020004@gmail.com> References: <48E58445.6050806@gmail.com> <48E70007.1020004@gmail.com> Message-ID: <95be1d3b0810040407xa4d4011v82eb16afe48cc77c@mail.gmail.com> Hi Serge, On Sat, Oct 4, 2008 at 07:32, Serge Aleynikov wrote: > I tried a similar test using jinterface to see if it's possible to > monitor processes running on a Java node and ran into the same failure. > (server)12> erlang:monitor(process, Pid). > ** exception error: bad argument > in function erlang:monitor/2 > called as erlang:monitor(process,<5979.1.0>) The documentation for erlang:monitor/2 says: "If an attempt is made to monitor a process on an older node (where remote process monitoring is not implemented or one where remote process monitoring by registered name is not implemented), the call fails with badarg. " The Java nodes aren't implementing everything that an Erlang node does, and I process monitoring is one of the things that is missing. In Java it is quite dificult (IMO) to have an Erlang-like setup with many mailboxes in separate threads. It gets hairy pretty fast. I am using only two mailboxes and then it is good enough to do the monitoring with erlang:monitor_node/1. I was considering to implement this kind of features for Java nodes, but never got enough time and motivation (you know, if it doesn't itch, one doesn't have to scratch it :-) regards, Vlad From pguyot Sat Oct 4 15:14:09 2008 From: pguyot (Paul Guyot) Date: Sat, 4 Oct 2008 15:14:09 +0200 Subject: [erlang-questions] jinterface (was: otp.net) In-Reply-To: References: Message-ID: <6C2A5378-5BDE-4FF9-B2AF-790D1F78330B@kallisys.net> > Date: Sat, 04 Oct 2008 01:32:55 -0400 > From: Serge Aleynikov > Subject: Re: [erlang-questions] jinterface (was: otp.net) > > I tried a similar test using jinterface to see if it's possible to > monitor processes running on a Java node and ran into the same > failure. > > Can anyone explain what's wrong? > > (server)10> {test, client} ! {self(), hello}. > {<0.45.0>,hello} > (server)11> f(), {Pid, _} = receive M -> M end. > {<5979.1.0>,hello} > (server)12> erlang:monitor(process, Pid). > ** exception error: bad argument > in function erlang:monitor/2 > called as erlang:monitor(process,<5979.1.0>) I've seen a comment in stdlib/gen.erl, at line 196, that suggests that Java and C nodes are featureweak, and processes in such nodes cannot be monitored. Instead, you have to monitor the whole node with monitor_node/2. This makes sense because the OTP ei (C library) or jinterface do not monitor "processes". Indeed, there is only one pid per node, which is the node's pseudo-pid (even if technically, each connection can receive messages). I guess you can draw from the code in gen.erl if you need to monitor either an erlang process or your java process, or just monitor the node if you only need to monitor java processes. Regards, Paul From saleyn Sat Oct 4 15:43:39 2008 From: saleyn (Serge Aleynikov) Date: Sat, 04 Oct 2008 09:43:39 -0400 Subject: [erlang-questions] jinterface In-Reply-To: <6C2A5378-5BDE-4FF9-B2AF-790D1F78330B@kallisys.net> References: <6C2A5378-5BDE-4FF9-B2AF-790D1F78330B@kallisys.net> Message-ID: <48E7730B.3090506@gmail.com> One other "nasty" feature is that any attempt to make an RPC call of io:format/2 from a Java/.NET node fails with badarg, because io server tries to set up a monitor to the remote pid and fails miserably... Actually I see what's missing in Java/OTP.NET implementation. These features are documented here: http://www.erlang.org/doc/apps/erts/erl_dist_protocol.html#9.7 Serge Paul Guyot wrote: >> Date: Sat, 04 Oct 2008 01:32:55 -0400 >> From: Serge Aleynikov >> Subject: Re: [erlang-questions] jinterface (was: otp.net) >> >> I tried a similar test using jinterface to see if it's possible to >> monitor processes running on a Java node and ran into the same failure. >> >> Can anyone explain what's wrong? >> >> (server)10> {test, client} ! {self(), hello}. >> {<0.45.0>,hello} >> (server)11> f(), {Pid, _} = receive M -> M end. >> {<5979.1.0>,hello} >> (server)12> erlang:monitor(process, Pid). >> ** exception error: bad argument >> in function erlang:monitor/2 >> called as erlang:monitor(process,<5979.1.0>) > > I've seen a comment in stdlib/gen.erl, at line 196, that suggests that > Java and C nodes are featureweak, and processes in such nodes cannot be > monitored. Instead, you have to monitor the whole node with > monitor_node/2. This makes sense because the OTP ei (C library) or > jinterface do not monitor "processes". Indeed, there is only one pid per > node, which is the node's pseudo-pid (even if technically, each > connection can receive messages). I guess you can draw from the code in > gen.erl if you need to monitor either an erlang process or your java > process, or just monitor the node if you only need to monitor java > processes. > > Regards, > > Paul > > From saleyn Sat Oct 4 15:17:35 2008 From: saleyn (Serge Aleynikov) Date: Sat, 04 Oct 2008 09:17:35 -0400 Subject: [erlang-questions] jinterface In-Reply-To: <95be1d3b0810040407xa4d4011v82eb16afe48cc77c@mail.gmail.com> References: <48E58445.6050806@gmail.com> <48E70007.1020004@gmail.com> <95be1d3b0810040407xa4d4011v82eb16afe48cc77c@mail.gmail.com> Message-ID: <48E76CEF.8080106@gmail.com> Vlad Dumitrescu wrote: > On Sat, Oct 4, 2008 at 07:32, Serge Aleynikov wrote: >> I tried a similar test using jinterface to see if it's possible to >> monitor processes running on a Java node and ran into the same failure. > >> (server)12> erlang:monitor(process, Pid). >> ** exception error: bad argument >> in function erlang:monitor/2 >> called as erlang:monitor(process,<5979.1.0>) > > The documentation for erlang:monitor/2 says: > > "If an attempt is made to monitor a process on an older node (where > remote process monitoring is not implemented or one where remote > process monitoring by registered name is not implemented), the call > fails with badarg. " > > The Java nodes aren't implementing everything that an Erlang node > does, and I process monitoring is one of the things that is missing. I guess I had higher hopes for jinterface (and consequently otp.net). :-( > In Java it is quite dificult (IMO) to have an Erlang-like setup with > many mailboxes in separate threads. It gets hairy pretty fast. I am > using only two mailboxes and then it is good enough to do the > monitoring with erlang:monitor_node/1. Actually, my overall goal was to establish the reverse - monitor an Erlang process from a .NET client (or java), where the client implements a UI application that establishes subscription with a process for receiving events of some sort, and tries to reestablish subscription if it detects that the remote process died. Serge From rvirding Sat Oct 4 16:11:56 2008 From: rvirding (Robert Virding) Date: Sat, 4 Oct 2008 16:11:56 +0200 Subject: [erlang-questions] jinterface In-Reply-To: <48E7730B.3090506@gmail.com> References: <6C2A5378-5BDE-4FF9-B2AF-790D1F78330B@kallisys.net> <48E7730B.3090506@gmail.com> Message-ID: <3dbc6d1c0810040711w26eae030pbcbccf7e1f4d5fd0@mail.gmail.com> It's not the io server which tries to setup a monitor, but the io module itself. These are two separate but cooperating entities. The io module monitors the io server to make sure that the call will not block if the process dies. The easiest way around this is to do the send/receive to the io serv yourself without a monitor. Robert 2008/10/4 Serge Aleynikov > One other "nasty" feature is that any attempt to make an RPC call of > io:format/2 from a Java/.NET node fails with badarg, because io server > tries to set up a monitor to the remote pid and fails miserably... > > Actually I see what's missing in Java/OTP.NET implementation. These > features are documented here: > http://www.erlang.org/doc/apps/erts/erl_dist_protocol.html#9.7 > > Serge > > > > Paul Guyot wrote: > >> Date: Sat, 04 Oct 2008 01:32:55 -0400 > >> From: Serge Aleynikov > >> Subject: Re: [erlang-questions] jinterface (was: otp.net) > >> > >> I tried a similar test using jinterface to see if it's possible to > >> monitor processes running on a Java node and ran into the same failure. > >> > >> Can anyone explain what's wrong? > >> > >> (server)10> {test, client} ! {self(), hello}. > >> {<0.45.0>,hello} > >> (server)11> f(), {Pid, _} = receive M -> M end. > >> {<5979.1.0>,hello} > >> (server)12> erlang:monitor(process, Pid). > >> ** exception error: bad argument > >> in function erlang:monitor/2 > >> called as erlang:monitor(process,<5979.1.0>) > > > > I've seen a comment in stdlib/gen.erl, at line 196, that suggests that > > Java and C nodes are featureweak, and processes in such nodes cannot be > > monitored. Instead, you have to monitor the whole node with > > monitor_node/2. This makes sense because the OTP ei (C library) or > > jinterface do not monitor "processes". Indeed, there is only one pid per > > node, which is the node's pseudo-pid (even if technically, each > > connection can receive messages). I guess you can draw from the code in > > gen.erl if you need to monitor either an erlang process or your java > > process, or just monitor the node if you only need to monitor java > > processes. > > > > Regards, > > > > Paul > > > > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081004/182c3f72/attachment.html From saleyn Sat Oct 4 16:49:27 2008 From: saleyn (Serge Aleynikov) Date: Sat, 04 Oct 2008 10:49:27 -0400 Subject: [erlang-questions] jinterface In-Reply-To: <3dbc6d1c0810040711w26eae030pbcbccf7e1f4d5fd0@mail.gmail.com> References: <6C2A5378-5BDE-4FF9-B2AF-790D1F78330B@kallisys.net> <48E7730B.3090506@gmail.com> <3dbc6d1c0810040711w26eae030pbcbccf7e1f4d5fd0@mail.gmail.com> Message-ID: <48E78277.4000809@gmail.com> Ah, I see, this makes sense. Meanwhile, I looked through the distribution sources, ei, and jinterface and see that it's not that difficult to add some monitoring support for non-Erlang nodes so that they can monitor Erlang pids. I'll patch otp.net and later ei if I find time this or next weekend. Serge Robert Virding wrote: > It's not the io server which tries to setup a monitor, but the io module > itself. These are two separate but cooperating entities. The io module > monitors the io server to make sure that the call will not block if the > process dies. The easiest way around this is to do the send/receive to the > io serv yourself without a monitor. > > Robert > > 2008/10/4 Serge Aleynikov > >> One other "nasty" feature is that any attempt to make an RPC call of >> io:format/2 from a Java/.NET node fails with badarg, because io server >> tries to set up a monitor to the remote pid and fails miserably... >> >> Actually I see what's missing in Java/OTP.NET implementation. These >> features are documented here: >> http://www.erlang.org/doc/apps/erts/erl_dist_protocol.html#9.7 >> >> Serge >> >> >> >> Paul Guyot wrote: >>>> Date: Sat, 04 Oct 2008 01:32:55 -0400 >>>> From: Serge Aleynikov >>>> Subject: Re: [erlang-questions] jinterface (was: otp.net) >>>> >>>> I tried a similar test using jinterface to see if it's possible to >>>> monitor processes running on a Java node and ran into the same failure. >>>> >>>> Can anyone explain what's wrong? >>>> >>>> (server)10> {test, client} ! {self(), hello}. >>>> {<0.45.0>,hello} >>>> (server)11> f(), {Pid, _} = receive M -> M end. >>>> {<5979.1.0>,hello} >>>> (server)12> erlang:monitor(process, Pid). >>>> ** exception error: bad argument >>>> in function erlang:monitor/2 >>>> called as erlang:monitor(process,<5979.1.0>) >>> I've seen a comment in stdlib/gen.erl, at line 196, that suggests that >>> Java and C nodes are featureweak, and processes in such nodes cannot be >>> monitored. Instead, you have to monitor the whole node with >>> monitor_node/2. This makes sense because the OTP ei (C library) or >>> jinterface do not monitor "processes". Indeed, there is only one pid per >>> node, which is the node's pseudo-pid (even if technically, each >>> connection can receive messages). I guess you can draw from the code in >>> gen.erl if you need to monitor either an erlang process or your java >>> process, or just monitor the node if you only need to monitor java >>> processes. >>> >>> Regards, >>> >>> Paul >>> >>> >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions >> http://www.erlang.org/mailman/listinfo/erlang-questions >> > From rvirding Sat Oct 4 16:57:42 2008 From: rvirding (Robert Virding) Date: Sat, 4 Oct 2008 16:57:42 +0200 Subject: [erlang-questions] jinterface In-Reply-To: <48E78277.4000809@gmail.com> References: <6C2A5378-5BDE-4FF9-B2AF-790D1F78330B@kallisys.net> <48E7730B.3090506@gmail.com> <3dbc6d1c0810040711w26eae030pbcbccf7e1f4d5fd0@mail.gmail.com> <48E78277.4000809@gmail.com> Message-ID: <3dbc6d1c0810040757u795d521ex4223ad37a4ab3900@mail.gmail.com> That would be a better solution in the long-run, but it is one which, unfortunately, I can't help you with. Robert 2008/10/4 Serge Aleynikov > Ah, I see, this makes sense. Meanwhile, I looked through the distribution > sources, ei, and jinterface and see that it's not that difficult to add some > monitoring support for non-Erlang nodes so that they can monitor Erlang > pids. I'll patch otp.net and later ei if I find time this or next > weekend. > > Serge > > > Robert Virding wrote: > >> It's not the io server which tries to setup a monitor, but the io module >> itself. These are two separate but cooperating entities. The io module >> monitors the io server to make sure that the call will not block if the >> process dies. The easiest way around this is to do the send/receive to the >> io serv yourself without a monitor. >> >> Robert >> >> 2008/10/4 Serge Aleynikov >> >> One other "nasty" feature is that any attempt to make an RPC call of >>> io:format/2 from a Java/.NET node fails with badarg, because io server >>> tries to set up a monitor to the remote pid and fails miserably... >>> >>> Actually I see what's missing in Java/OTP.NET implementation. These >>> features are documented here: >>> http://www.erlang.org/doc/apps/erts/erl_dist_protocol.html#9.7 >>> >>> Serge >>> >>> >>> >>> Paul Guyot wrote: >>> >>>> Date: Sat, 04 Oct 2008 01:32:55 -0400 >>>>> From: Serge Aleynikov >>>>> Subject: Re: [erlang-questions] jinterface (was: otp.net) >>>>> >>>>> I tried a similar test using jinterface to see if it's possible to >>>>> monitor processes running on a Java node and ran into the same failure. >>>>> >>>>> Can anyone explain what's wrong? >>>>> >>>>> (server)10> {test, client} ! {self(), hello}. >>>>> {<0.45.0>,hello} >>>>> (server)11> f(), {Pid, _} = receive M -> M end. >>>>> {<5979.1.0>,hello} >>>>> (server)12> erlang:monitor(process, Pid). >>>>> ** exception error: bad argument >>>>> in function erlang:monitor/2 >>>>> called as erlang:monitor(process,<5979.1.0>) >>>>> >>>> I've seen a comment in stdlib/gen.erl, at line 196, that suggests that >>>> Java and C nodes are featureweak, and processes in such nodes cannot be >>>> monitored. Instead, you have to monitor the whole node with >>>> monitor_node/2. This makes sense because the OTP ei (C library) or >>>> jinterface do not monitor "processes". Indeed, there is only one pid per >>>> node, which is the node's pseudo-pid (even if technically, each >>>> connection can receive messages). I guess you can draw from the code in >>>> gen.erl if you need to monitor either an erlang process or your java >>>> process, or just monitor the node if you only need to monitor java >>>> processes. >>>> >>>> Regards, >>>> >>>> Paul >>>> >>>> >>>> _______________________________________________ >>> erlang-questions mailing list >>> erlang-questions >>> http://www.erlang.org/mailman/listinfo/erlang-questions >>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081004/b43b0097/attachment-0001.html From dawsdesign Sat Oct 4 17:21:36 2008 From: dawsdesign (Matt Williamson) Date: Sat, 4 Oct 2008 11:21:36 -0400 Subject: [erlang-questions] OTP.NET Error In-Reply-To: <48E6D720.1080404@gmail.com> References: <48E6D720.1080404@gmail.com> Message-ID: Yep, that did it. ???????! On Fri, Oct 3, 2008 at 10:38 PM, Serge Aleynikov wrote: > I took a quick look at your code and see that you are doing this on every > button click which is wrong: > > OtpSelf self = new OtpSelf("client", "abc123"); > OtpPeer server = new OtpPeer("server"); > OtpConnection connection = server.connect(self); > > Move that to form initialization function, and try again. I guess what's > going on is that OtpAbstractNode doesn't implement proper destruction and > freeing resources (the socket connection), and as a result on every button > click you are trying to set up more than one connection with the Erlang > server node, which is not allowed, so the server drops the second and > following connection attempts. > > Serge > > > Matt Williamson wrote: > >> I'm trying out a simple OTP.NET test and it works great for the first >> call, >> but any subsequent calls result in the following exception: >> System.IO.IOException was unhandled >> Message="Peer replied with status 'alive' instead of 'ok'" >> Source="Otp" >> StackTrace: >> at Otp.AbstractConnection.recvStatus() in C:\Documents and >> Settings\Administrator\Desktop\jungerl\lib\otp.net >> \Otp\AbstractConnection.cs:line >> 1455 >> at Otp.AbstractConnection.doConnect(Int32 port) in C:\Documents and >> Settings\Administrator\Desktop\jungerl\lib\otp.net >> \Otp\AbstractConnection.cs:line >> 1018 >> at Otp.AbstractConnection..ctor(OtpLocalNode self, OtpPeer other) in >> C:\Documents and >> Settings\Administrator\Desktop\jungerl\lib\otp.net >> \Otp\AbstractConnection.cs:line >> 226 >> at Otp.OtpConnection..ctor(OtpSelf self, OtpPeer other) in >> C:\Documents and >> Settings\Administrator\Desktop\jungerl\lib\otp.net >> \Otp\OtpConnection.cs:line >> 84 >> at Otp.OtpPeer.connect(OtpSelf self) in C:\Documents and >> Settings\Administrator\Desktop\jungerl\lib\otp.net\Otp\OtpPeer.cs:line 67 >> at ErlTestClient.Form1.button1_Click(Object sender, EventArgs e) in >> C:\Documents and Settings\Administrator\My >> Documents\Projects\ErlTestClient\ErlTestClient\Form1.cs:line 25 >> at System.Windows.Forms.Control.OnClick(EventArgs e) >> at System.Windows.Forms.Button.OnClick(EventArgs e) >> at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) >> at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons >> button, Int32 clicks) >> at System.Windows.Forms.Control.WndProc(Message& m) >> at System.Windows.Forms.ButtonBase.WndProc(Message& m) >> at System.Windows.Forms.Button.WndProc(Message& m) >> at >> System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) >> at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& >> m) >> at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, >> Int32 msg, IntPtr wparam, IntPtr lparam) >> at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& >> msg) >> at >> >> System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 >> dwComponentID, Int32 reason, Int32 pvLoopData) >> at >> System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 >> reason, ApplicationContext context) >> at >> System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 >> reason, >> ApplicationContext context) >> at System.Windows.Forms.Application.Run(Form mainForm) >> at ErlTestClient.Program.Main() in C:\Documents and >> Settings\Administrator\My >> Documents\Projects\ErlTestClient\ErlTestClient\Program.cs:line 17 >> at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] >> args) >> at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence >> assemblySecurity, String[] args) >> at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() >> at System.Threading.ThreadHelper.ThreadStart_Context(Object state) >> at System.Threading.ExecutionContext.Run(ExecutionContext >> executionContext, ContextCallback callback, Object state) >> at System.Threading.ThreadHelper.ThreadStart() >> >> >> You can view my source at http://paste.lisp.org/display/67861 and >> http://paste.lisp.org/display/67862 >> >> Erlang is v5.6.3 on windows and I'm running VS2005. >> >> Please help :) >> >> >> >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions >> http://www.erlang.org/mailman/listinfo/erlang-questions >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081004/e0e2f895/attachment.html From greg.burri Sat Oct 4 18:19:53 2008 From: greg.burri (Greg Burri) Date: Sat, 4 Oct 2008 18:19:53 +0200 Subject: [erlang-questions] Get a range of tuples from a Mnesia table Message-ID: <60ed8a460810040919qcf9dd37m994bbf6932f18cc0@mail.gmail.com> Hi, I want to retrieve N tuple with an offset O from the end of a table. N and O are integer(). I consider that the acces is based on an ordered table. Here is an example, I have such tuples in my table t : [{t, 1, _}, {t, 2, _}, {t, 3, _}, {t, 4, _}, {t, 5, _}, {t, 6, _}, {t, 7, _}] For N=2 and O=3 the result will be : [{t, 4, _}, {t, 5, _}] For now I have to use an ordered_set table and the functions mnesia:last/1 and mnesia:prev/2, it works but the complexity is O(O). If I have to get some tuple from the middle of the table it will take long time. Is there an another solution than mine ? Second question : How change the type of a table from set to ordered_set on an existing table ? /Greg Burri -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081004/9eb64d2e/attachment.html From vladdu55 Sat Oct 4 20:02:21 2008 From: vladdu55 (Vlad Dumitrescu) Date: Sat, 4 Oct 2008 20:02:21 +0200 Subject: [erlang-questions] jinterface In-Reply-To: <48E7730B.3090506@gmail.com> References: <6C2A5378-5BDE-4FF9-B2AF-790D1F78330B@kallisys.net> <48E7730B.3090506@gmail.com> Message-ID: <95be1d3b0810041102r5fbfd2f6t5e54c2551926e226@mail.gmail.com> On Sat, Oct 4, 2008 at 15:43, Serge Aleynikov wrote: > Actually I see what's missing in Java/OTP.NET implementation. These > features are documented here: > http://www.erlang.org/doc/apps/erts/erl_dist_protocol.html#9.7 Even if those features were implemented, the Java VM is still not the BEAM VM, so it wouldn't be te same anyway. The impedance mismatch between the two runtime models is too large to integrate them seamlessly. > Actually, my overall goal was to establish the reverse - monitor an Erlang process > from a .NET client (or java), where the client implements a UI application that > establishes subscription with a process for receiving events of some sort, and > tries to reestablish subscription if it detects that the remote process died. Then you are in luck, because it can be done! Start a process that will do the monitoring and let it forward the messages to the Java side. This proxying technique can be applied in many other contexts, too. For example, for the io:format problem, you can start a io server that works as a proxy for the missing one on the Java side. But you may find soon that you will prefer to move more and more functionality on the Erlang side and use Java just as a presentation layer. best regards, Vlad From erlang-questions_efine Sat Oct 4 20:11:06 2008 From: erlang-questions_efine (Edwin Fine) Date: Sat, 4 Oct 2008 14:11:06 -0400 Subject: [erlang-questions] Get a range of tuples from a Mnesia table In-Reply-To: <60ed8a460810040919qcf9dd37m994bbf6932f18cc0@mail.gmail.com> References: <60ed8a460810040919qcf9dd37m994bbf6932f18cc0@mail.gmail.com> Message-ID: <6c2563b20810041111t401ebb0fh5482d383438f0b8b@mail.gmail.com> Looking through the docs, I see that if you are using an mnesia table that is ram_copies or disc_copies, you can do certain fast operations on the associated ets table. One such operation (which is recommended only for debugging, but what the heck) is ets:slot(Tab, I), which returns the I'th record in the table. So maybe you could find a way to do that on the ETS table that Mnesia is using, perhaps via the mnesia:ets() function. I have never tried this so it's just a guess. This is also kind of a hack but other than reading through the mnesia code, I can't locate something better. Maybe one of the real Mnesia gurus will have an idea. 2008/10/4 Greg Burri > Hi, > I want to retrieve N tuple with an offset O from the end of a table. N and > O are integer(). I consider that the acces is based on an ordered table. > > Here is an example, I have such tuples in my table t : > [{t, 1, _}, > {t, 2, _}, > {t, 3, _}, > {t, 4, _}, > {t, 5, _}, > {t, 6, _}, > {t, 7, _}] > > For N=2 and O=3 the result will be : > [{t, 4, _}, {t, 5, _}] > > For now I have to use an ordered_set table and the functions mnesia:last/1 > and mnesia:prev/2, it works but the complexity is O(O). If I have to get > some tuple from the middle of the table it will take long time. > Is there an another solution than mine ? > > Second question : How change the type of a table from set to ordered_set on > an existing table ? > > > /Greg Burri > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081004/a2444932/attachment.html From rvirding Sat Oct 4 20:15:22 2008 From: rvirding (Robert Virding) Date: Sat, 4 Oct 2008 20:15:22 +0200 Subject: [erlang-questions] extending the scanner and parser In-Reply-To: <95be1d3b0810031126t5fb7b8b9x48bb75c3895a330e@mail.gmail.com> References: <95be1d3b0810030413p52bc5b58uf22c6790d64f9f35@mail.gmail.com> <20081003151527.GA28655@myrtle.kent.ac.uk> <95be1d3b0810031126t5fb7b8b9x48bb75c3895a330e@mail.gmail.com> Message-ID: <3dbc6d1c0810041115p571160fft458be1a867ff6cf2@mail.gmail.com> Another solution which may help you is to use leex for generating the scanner. It gives you much more freedom in deciding what to return, so you could return both the value and/or the chars if you wish. However, I don't think it will give all the data you want, you can the line number, characters and length of each token. If you want to use yecc for generating the parser, which really does simplify matters, you have to a little circumspect because it only accepts tokens in the form {Type,Line} or {Type,Line,Value}. It does place any restrictions on the vaule. Robert 2008/10/3 Vlad Dumitrescu > On Fri, Oct 3, 2008 at 18:18, Kenneth Lundin > wrote: > > It is in our plans to have that support in our standard scanner in some > way. > > Can not promise when but hopefully next year some time. > > That's wonderful to know! > > I suppose that it wouldn't hurt if we (the tool makers) would start > right away to tinker with it so that when you're ready you will have > something almost ready to work with, would it? > > best regards, > Vlad > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081004/4e4a6070/attachment-0001.html From vladdu55 Sat Oct 4 20:27:56 2008 From: vladdu55 (Vlad Dumitrescu) Date: Sat, 4 Oct 2008 20:27:56 +0200 Subject: [erlang-questions] extending the scanner and parser In-Reply-To: <3dbc6d1c0810041115p571160fft458be1a867ff6cf2@mail.gmail.com> References: <95be1d3b0810030413p52bc5b58uf22c6790d64f9f35@mail.gmail.com> <20081003151527.GA28655@myrtle.kent.ac.uk> <95be1d3b0810031126t5fb7b8b9x48bb75c3895a330e@mail.gmail.com> <3dbc6d1c0810041115p571160fft458be1a867ff6cf2@mail.gmail.com> Message-ID: <95be1d3b0810041127o3d733f09l5182c0499ee57daa@mail.gmail.com> On Sat, Oct 4, 2008 at 20:15, Robert Virding wrote: > Another solution which may help you is to use leex for generating the > scanner. It gives you much more freedom in deciding what to return, so you > could return both the value and/or the chars if you wish. However, I don't > think it will give all the data you want, you can the line number, > characters and length of each token. > > If you want to use yecc for generating the parser, which really does > simplify matters, you have to a little circumspect because it only accepts > tokens in the form {Type,Line} or {Type,Line,Value}. It does place any > restrictions on the vaule. Thank you for the advice! I considered that, but I'd rather use the standard lexer and parser, to be sure the results are exactly the same as they should (except the presentation). Actually, now that I think of it, I did try it, but got trouble with the more esoteric parts (like multi-line strings) and abandoned that path. Maintenance would still be a headache. best regards, Vlad From cktgatb Sun Oct 5 05:16:23 2008 From: cktgatb (deepblue_other) Date: Sat, 4 Oct 2008 20:16:23 -0700 (PDT) Subject: [erlang-questions] tcp sockets confusion Message-ID: <19803972.post@talk.nabble.com> hello everyone Im building a system with a Flash front-end and an Erlang back-end and have some confusion in a case where there is a single socket on the back-end per user (per single socket on the front-end). I want to have multiple independent objects on the front-end send messages to the back-end, but am not sure how the simultaneous transmission would be handled. This probably stems from my somewhat clowdly understanding of TCP. Say there are 3 objects that initiate a send() method on the front-end (almost at the same time) and send a semi large message each to the back-end. Each message would be ID'd by the front-end so that when received back it can be routed to the appropriate callback. Is this possible? since the packets are being assembled in the {tcp, Socket, Data} pattern match, peace by peace, would the correct peaces of the individual messages be stiched together? (doesnt seem like they would). if that wont work then I would just have the serialize the sending/receiving, which is not too horrible... thanks -- View this message in context: http://www.nabble.com/tcp-sockets-confusion-tp19803972p19803972.html Sent from the Erlang Questions mailing list archive at Nabble.com. From cktgatb Sun Oct 5 05:19:04 2008 From: cktgatb (deepblue_other) Date: Sat, 4 Oct 2008 20:19:04 -0700 (PDT) Subject: [erlang-questions] re cursive fun() Message-ID: <19820386.post@talk.nabble.com> hello I have this going on FunVar = fun() -> ... FunVar() end. so the compiler is complaining that FunVar is unbound at the place where its being used inside fun(); this makes sense, however Im wondering how to make this into a recursive function since there's no name to reference the function with. thanks -- View this message in context: http://www.nabble.com/recursive-fun%28%29-tp19820386p19820386.html Sent from the Erlang Questions mailing list archive at Nabble.com. From bgustavsson Sun Oct 5 08:32:38 2008 From: bgustavsson (Bjorn Gustavsson) Date: Sun, 5 Oct 2008 08:32:38 +0200 Subject: [erlang-questions] Unused inline functions compiler warning In-Reply-To: <6c2563b20810031202u6dcf65bdqa88d2c09c193376b@mail.gmail.com> References: <6c2563b20810031202u6dcf65bdqa88d2c09c193376b@mail.gmail.com> Message-ID: <6672d0160810042332s4d7e8c90kd3cb44d136182ecd@mail.gmail.com> 2008/10/3 Edwin Fine > Does this imply that every inline function in a .hrl file will be inserted > into every single .erl file that includes it, even if it is unused? If not, > then why have a compiler warning? > No, the compiler will always remove unused local functions. The compiler always warns for unused functions, to help you get rid of old functions that are no longer used. I suppose it could be reasonable if the compiler suppressed the warning for functions that are defined in .hrl files (in the same way that it only warns for unused records in .erl files, never in .hrl files). If there are no strong objections either here or in the Erlang/OTP group, we might change that for R12B-5 release. > > Is there any way to overcome this without reverting back to using macros? > > Can I get rid of just those warnings? Is there a way to suppress warnings > for individual functions, like a -compile({suppress, [{wunused, > [{log_info,3},{log_dbg,3}]}]})? > > There is currently no way to suppress individual warnings. We have been thinking about adding such a mechanism. /Bjorn -- Bj?rn Gustavsson, Erlang/OTP, Ericsson AB -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081005/1f91fdc3/attachment.html From bgustavsson Sun Oct 5 08:45:16 2008 From: bgustavsson (Bjorn Gustavsson) Date: Sun, 5 Oct 2008 08:45:16 +0200 Subject: [erlang-questions] [bug] beam_asm failure on invalid binary match In-Reply-To: References: Message-ID: <6672d0160810042345m6c72a3a2r5087f816492e3121@mail.gmail.com> 2008/10/3 Will > Hello, > > I mistakenly set the size specifier in a binary match to zero and it caused > beam_asm to crash. > This is Erlang/OTP R12B-4. > Thanks! We will fix that bug in R12B-5. /Bjorn -- Bj?rn Gustavsson, Erlang/OTP, Ericsson AB -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081005/d2eb6df8/attachment.html From bgustavsson Sun Oct 5 08:43:39 2008 From: bgustavsson (Bjorn Gustavsson) Date: Sun, 5 Oct 2008 08:43:39 +0200 Subject: [erlang-questions] Unused inline functions compiler warning In-Reply-To: <6672d0160810042332s4d7e8c90kd3cb44d136182ecd@mail.gmail.com> References: <6c2563b20810031202u6dcf65bdqa88d2c09c193376b@mail.gmail.com> <6672d0160810042332s4d7e8c90kd3cb44d136182ecd@mail.gmail.com> Message-ID: <6672d0160810042343k43a304b5i888a78944c87e008@mail.gmail.com> On Sun, Oct 5, 2008 at 8:32 AM, Bjorn Gustavsson wrote: > 2008/10/3 Edwin Fine >> >> >> Can I get rid of just those warnings? Is there a way to suppress warnings >> for individual functions, like a -compile({suppress, [{wunused, >> [{log_info,3},{log_dbg,3}]}]})? >> >> There is currently no way to suppress individual warnings. We have been > thinking about adding such a mechanism. > Unfortunately, I didn't check the compiler documentation before answering. As you wrote in another email, this particular warning *can* be suppressed. There are still other warnings that cannot be suppressed, unfortunately, and there is an item on my to-do list to fix that. /Bjorn > > -- Bj?rn Gustavsson, Erlang/OTP, Ericsson AB -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081005/1e7474a8/attachment.html From erlang-questions_efine Sun Oct 5 11:13:41 2008 From: erlang-questions_efine (Edwin Fine) Date: Sun, 5 Oct 2008 05:13:41 -0400 Subject: [erlang-questions] re cursive fun() In-Reply-To: <19820386.post@talk.nabble.com> References: <19820386.post@talk.nabble.com> Message-ID: <6c2563b20810050213r7ea28fdbp9b2205332b3662a2@mail.gmail.com> I'm assuming that you want to do this in the shell, otherwise it would be easier just to write the function in the usual way, e.g. myfun() -> blah, blah, myfun(). To create a fun that calls itself, you must realize that you are creating an unnamed function. When you write fun(X) -> X * 2 end. this is compiled to a Fun data type, e.g. #Fun. Since the function does not have a name, it cannot refer to itself. When you write FunVar = fun(X) -> X * 2 end, the function is bound to the variable FunVar. Because the binding takes place *after* the fun is created, the fun cannot refer to the variable FunVar within its definition. So how is it done? You have to pass the variable to the function so that it "knows" what to call: FunVar = fun(MySelf) -> ... MySelf(). Then when you call it, you call FunVar(FunVar). Looks strange but it works. Example: Writing a simple generate and fold function using only a fun() variable. 9> GenFold = fun(0, Acc, _) -> Acc; (X, Acc, Fun) -> Fun(X - 1, [X|Acc], Fun) end. #Fun 10> GenFold(10, [], GenFold). [1,2,3,4,5,6,7,8,9,10] 11> Or a for loop: 22> For = fun(Max, Max, ExecFun, _) -> ok; (N, Max, ExecFun, Next) -> ExecFun(N), Next(N + 1, Max, ExecFun, Next) end. #Fun 23> For(0,10,fun(I) -> io:format("~B ", [I]) end, For). 0 1 2 3 4 5 6 7 8 9 ok 24> Stuff like this is described in Joe Armstrong's Erlang book. Hope this helps. On Sat, Oct 4, 2008 at 11:19 PM, deepblue_other wrote: > > hello > I have this going on > > FunVar = > fun() -> > ... > FunVar() > end. > > so the compiler is complaining that FunVar is unbound at the place where > its > being used inside fun(); this makes sense, however Im wondering how to make > this into a recursive function since there's no name to reference the > function with. > > thanks > -- > View this message in context: > http://www.nabble.com/recursive-fun%28%29-tp19820386p19820386.html > Sent from the Erlang Questions mailing list archive at Nabble.com. > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081005/26131d48/attachment.html From richardc Sun Oct 5 11:30:22 2008 From: richardc (Richard Carlsson) Date: Sun, 05 Oct 2008 11:30:22 +0200 Subject: [erlang-questions] re cursive fun() In-Reply-To: <19820386.post@talk.nabble.com> References: <19820386.post@talk.nabble.com> Message-ID: <48E8892E.5040204@it.uu.se> deepblue_other wrote: > hello > I have this going on > > FunVar = > fun() -> > ... > FunVar() > end. > > so the compiler is complaining that FunVar is unbound at the place where its > being used inside fun(); this makes sense, however Im wondering how to make > this into a recursive function since there's no name to reference the > function with. You have to make it keep "itself" around as an additional parameter, so that you can first create it and then hand it the self-reference: FunVar = fun(Myself) -> ... Myself(Myself) end then call it like this: FunVar(FunVar). If you want the result to be a function of arity 0, as in your example, then replace the last line with FinalFunVar = fun () -> FunVar(FunVar) end /Richard -- "Having users is like optimization: the wise course is to delay it." -- Paul Graham From exta7 Sun Oct 5 11:58:34 2008 From: exta7 (Zvi) Date: Sun, 5 Oct 2008 02:58:34 -0700 (PDT) Subject: [erlang-questions] Hungarian notation for Erlang / ETL In-Reply-To: <14710892.post@talk.nabble.com> References: <14701912.post@talk.nabble.com> <14710892.post@talk.nabble.com> Message-ID: <19822958.post@talk.nabble.com> Nick Gerakines blogging about need for "Standard Collection behaviour" in Erlang http://blog.socklabs.com/2008/10/erlang_woes/ Zvi Zvi wrote: > > 1. I also hate Hungarian notation and doesn't use it even in C++ (except > m_ prefix), but I still need a solution for current version of Elrang > (does it mean that I need always use Dyalizer?). > > 2. I wasn't talking about implementing object using Erlang processes. I > talking about much simpler and functional solution, like providing > behaviour, like: > > -module(collection). > -export([behaviour_info/1]). > > behaviour_info(callbacks) -> > [{new,0}, > {length,1}, > {to_string,1}, > {from_string,1}, > {map,2}, > {foldl,2}, > {foldr,2}, > {sort,1}, > %% etc... > ]; > behaviour_info(_Other) -> > undefined. > > then each ADT will implement this bahaviour, like: > > -module(queue). > -behaviour(collection). > > %% ... > > -module(set). > -behaviour(collection). > > %% ... > > -module(stack). > -behaviour(collection). > > %% ... > > > etc. > > Zvi > > > David Holz wrote: >> >> >> From: exta7 >>> Is there some kind of Hungarian notation for Erlang? i.e. prefix or >>> postfix >>> naming convention. >> >> Hungarian notation is the absolute wrong solution to type confusion (or >> any other problem). The new type annotations will eventually provide >> optional type information available to both the compiler and IDEs for >> keeping things straight. It won't be long before it's an official part >> of the release; the annotation handling is in there already, just not >> documented. >> >> I would, though, also like to see some sort of actual OO-ish interface to >> a block of data that can dispatch to the proper behavior for that >> specific data term. Java's collections and IO streams, while verbose, >> are incredibly usable implementations of that idea at their core. With >> Erlang, however, it might mean that your data item is held by its own >> process, with a well-defined messaging interface, and might want some >> sort of automatic deferring to a parent process/module for unhandled >> calls or messages in the receive loop. >> >> _________________________________________________________________ >> Share life as it happens with the new Windows Live. >> http://www.windowslive.com/share.html?ocid=TXT_TAGHM_Wave2_sharelife_012008 >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions >> http://www.erlang.org/mailman/listinfo/erlang-questions >> >> > > -- View this message in context: http://www.nabble.com/Hungarian-notation-for-Erlang---ETL-tp14701912p19822958.html Sent from the Erlang Questions mailing list archive at Nabble.com. From jan Sun Oct 5 13:02:20 2008 From: jan (Jan Lehnardt) Date: Sun, 5 Oct 2008 13:02:20 +0200 Subject: [erlang-questions] Introduction to Erlang at Erlang User Group Berlin Message-ID: Dear Erlang Folks in Berlin and thereabouts, This month's Erlang User Group[1] meeting will sport an "Introduction to Erlang" by Florian Ebeling. Florian stepped up to satisfy frequent request by newcomers to give a introductory presentation about Erlang. Thanks Florian! This event is open to everyone, not just members of the Erlang User. Please give us a shout on the Google Group [1] if you are planning to come. We meet at Z-Bar[2], Bergstr.2, Berlin Mitte[3], 20:00 on October 8th, 2008, listen to Florian's presentation and then have a few beers. Please spread the word, thank you! Cheers, Jan -- [1] http://groups.google.com/group/erlang-berlin [2] http://z-bar.de/ [3] http://maps.google.com/maps?f=q&hl=en&geocode=&q=z-bar&sll=52.491349,13.427872&sspn=0.006637,0.013733&ie=UTF8&ll=52.531887,13.401947&spn=0.053048,0.109863&z=13 From bbmaj7 Sun Oct 5 12:12:16 2008 From: bbmaj7 (Richard Andrews) Date: Sun, 5 Oct 2008 03:12:16 -0700 (PDT) Subject: [erlang-questions] re cursive fun() Message-ID: <58013.1460.qm@web65508.mail.ac4.yahoo.com> > FunVar = > fun() -> > ... > FunVar() > end. > > so the compiler is complaining that FunVar is unbound at the place where its > being used inside fun(); this makes sense, however Im wondering how to make > this into a recursive function since there's no name to reference the > function with. Maybe have the fun call a real (recursive) function. eg. F(A) -> ... F(B). Caller(Data) -> ... FunVar = fun(A) -> F(A) end, ... foo:use_fun(FunVar, Data). -- Rich Make the switch to the world's best email. Get Yahoo!7 Mail! http://au.yahoo.com/y7mail From 0x6e6562 Sun Oct 5 13:20:59 2008 From: 0x6e6562 (Ben Hood) Date: Sun, 5 Oct 2008 12:20:59 +0100 Subject: [erlang-questions] Some mnesia oddity In-Reply-To: <48B7DB67.7010608@erix.ericsson.se> References: <48B7DB67.7010608@erix.ericsson.se> Message-ID: <269388e30810050420w38e3cc77h23dea901c39d6cc1@mail.gmail.com> Hi, I know this is an old thread but I was wondering where the behaviour I am seeing is in any way related to passing in a pattern to mnesia:delete_object/1. On Fri, Aug 29, 2008 at 12:20 PM, Dan Gudmundsson wrote: >> We found a strange mnesia behavior here... >> >> Some mnesia:write operations after a mnesia:delete_object seem to >> not have the expected result when executed in the same transaction. >> >> See attached example file: >> 1 - We fill a test_table >> 2 - In the same transaction, we read all records, delete them, and >> write them back (do not ask why :)) >> 3 - Surprise! Only a subset of them can be read afterwards >> >> Same result in R11 and R12. >> >> It works if the delete_object and write operations are in separate >> transactions... But who knows what can happen between them... The code I am using (attached below) is similar to the above scenario. Basically what I want to know is if there is a way to delete records from a table and then re-read the table in the same transaction, or whether this must be in separate transactions. My use case is a densely populated table that I want to 1. Selectively delete some records for; 2. Conditionally delete records from a different table if they no longer have any references in the first table. So my approach could be characterized by a delete and sweep action. Of course I could implement this functionality manually by re-reading the table and filtering out any results that I know will get deleted when the transaction commits. But if I could get mnesia to do this, it would be more elegant. Also, I could do this in two transactions and re-arrange the code so to introduce something idempotent to get around the non-atomicity. But if this could be solved using mnesia, that would be cool :-) Thx, Ben ---snip--- -module(sync_test). -compile(export_all). -record(outer,{inner, const = const}). -record(inner,{a,b,c}). init() -> mnesia:start(), mnesia:delete_table(outer), {atomic,ok} = mnesia:create_table(outer, [{type,ordered_set}, {attributes, record_info(fields, outer)}]), ok. insert() -> Record = #outer{inner = #inner{a = 1, b = 2, c = now()}}, mnesia:transaction(fun() -> mnesia:write(Record) end). one_tx() -> Record = #outer{inner = #inner{a = 1, b = 2, c = '_'}}, mnesia:sync_transaction( fun() -> mnesia:delete_object(Record), io:format("~p~n",[mnesia:match_object(Record)]) end). two_tx() -> Record = #outer{inner = #inner{a = 1, b = 2, c = '_'}}, mnesia:sync_transaction( fun() -> mnesia:delete_object(Record) end), mnesia:sync_transaction( fun() -> io:format("~p~n",[mnesia:match_object(Record)]) end). From ciprian.craciun Sun Oct 5 16:11:57 2008 From: ciprian.craciun (Ciprian Dorin Craciun) Date: Sun, 5 Oct 2008 17:11:57 +0300 Subject: [erlang-questions] re cursive fun() In-Reply-To: <48E8892E.5040204@it.uu.se> References: <19820386.post@talk.nabble.com> <48E8892E.5040204@it.uu.se> Message-ID: <8e04b5820810050711s5d4ef554v50131c481fa19e85@mail.gmail.com> On Sun, Oct 5, 2008 at 12:30 PM, Richard Carlsson wrote: > deepblue_other wrote: >> hello >> I have this going on >> >> FunVar = >> fun() -> >> ... >> FunVar() >> end. >> >> so the compiler is complaining that FunVar is unbound at the place where its >> being used inside fun(); this makes sense, however Im wondering how to make >> this into a recursive function since there's no name to reference the >> function with. > > You have to make it keep "itself" around as an additional parameter, > so that you can first create it and then hand it the self-reference: > > FunVar = > fun(Myself) -> > ... > Myself(Myself) > end > > then call it like this: > > FunVar(FunVar). > > If you want the result to be a function of arity 0, > as in your example, then replace the last line with > > FinalFunVar = fun () -> FunVar(FunVar) end > > /Richard > > -- > "Having users is like optimization: the wise course is to delay it." > -- Paul Graham About this subject, I would ask if isn't it better / easier / clearer to add a special function name / keyword that would refer to the function itself. This would also have a few advantages: * first it will solve the recursivity problem described above; * (maybe) it could also improve efficiency (because you know exactly what function you're calling, without any lookup); (this is just an assumption, maybe inside the beam file the lookup does not exist); (certainly it is more efficient than the proposed solution --- sending the function as an argument;) * it will assist in refactoring --- changing a recursive function name will have no impact on it's code; * it could clearly mark the fact that the function calls itself. As for disadvantages I really do not see any. (Except of having a new keyword / special function.) So any comments? Ciprian. P.S.: I think this solution could be equally applied to all languages (mainly Lisp like). From erlang-questions_efine Sun Oct 5 17:03:49 2008 From: erlang-questions_efine (Edwin Fine) Date: Sun, 5 Oct 2008 11:03:49 -0400 Subject: [erlang-questions] re cursive fun() In-Reply-To: <6c2563b20810050213r7ea28fdbp9b2205332b3662a2@mail.gmail.com> References: <19820386.post@talk.nabble.com> <6c2563b20810050213r7ea28fdbp9b2205332b3662a2@mail.gmail.com> Message-ID: <6c2563b20810050803w3c25c122yd878f14a6b11cbb3@mail.gmail.com> Just noticed a mistake. FunVar = fun(MySelf) -> ... MySelf(). should have been FunVar = fun(MySelf) -> ... MySelf(MySelf). On Sun, Oct 5, 2008 at 5:13 AM, Edwin Fine wrote: > I'm assuming that you want to do this in the shell, otherwise it would be > easier just to write the function in the usual way, e.g. > > myfun() -> > blah, blah, > myfun(). > > To create a fun that calls itself, you must realize that you are creating > an unnamed function. When you write > > fun(X) -> X * 2 end. > > this is compiled to a Fun data type, e.g. #Fun. > > Since the function does not have a name, it cannot refer to itself. > > When you write FunVar = fun(X) -> X * 2 end, the function is bound to the > variable FunVar. Because the binding takes place *after* the fun is created, > the fun cannot refer to the variable FunVar within its definition. > > So how is it done? You have to pass the variable to the function so that it > "knows" what to call: > > FunVar = > fun(MySelf) -> > ... > MySelf(). > > Then when you call it, you call FunVar(FunVar). Looks strange but it works. > > Example: Writing a simple generate and fold function using only a fun() > variable. > > 9> GenFold = > fun(0, Acc, _) -> > Acc; > (X, Acc, Fun) -> > Fun(X - 1, [X|Acc], Fun) > end. > #Fun > 10> GenFold(10, [], > GenFold). > [1,2,3,4,5,6,7,8,9,10] > 11> > > Or a for loop: > > 22> For = > fun(Max, Max, ExecFun, _) -> > ok; > (N, Max, ExecFun, Next) -> > ExecFun(N), > Next(N + 1, Max, ExecFun, Next) > end. > #Fun > 23> For(0,10,fun(I) -> io:format("~B ", [I]) end, > For). > > 0 1 2 3 4 5 6 7 8 9 ok > 24> > > Stuff like this is described in Joe Armstrong's Erlang book. > > Hope this helps. > > > On Sat, Oct 4, 2008 at 11:19 PM, deepblue_other wrote: > >> >> hello >> I have this going on >> >> FunVar = >> fun() -> >> ... >> FunVar() >> end. >> >> so the compiler is complaining that FunVar is unbound at the place where >> its >> being used inside fun(); this makes sense, however Im wondering how to >> make >> this into a recursive function since there's no name to reference the >> function with. >> >> thanks >> -- >> View this message in context: >> http://www.nabble.com/recursive-fun%28%29-tp19820386p19820386.html >> Sent from the Erlang Questions mailing list archive at Nabble.com. >> >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions >> http://www.erlang.org/mailman/listinfo/erlang-questions >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081005/fba6354f/attachment.html From cktgatb Sun Oct 5 17:12:21 2008 From: cktgatb (deepblue_other) Date: Sun, 5 Oct 2008 08:12:21 -0700 (PDT) Subject: [erlang-questions] re cursive fun() In-Reply-To: <6c2563b20810050213r7ea28fdbp9b2205332b3662a2@mail.gmail.com> References: <19820386.post@talk.nabble.com> <6c2563b20810050213r7ea28fdbp9b2205332b3662a2@mail.gmail.com> Message-ID: <19825467.post@talk.nabble.com> Edwin Fine-2 wrote: > > I'm assuming that you want to do this in the shell, otherwise it would be > easier just to write the function in the usual way, e.g. > > myfun() -> > blah, blah, > myfun(). > no shell is not the reason, I need a function that will only be called from within another function and I dont want to "pollute" the "module wide" space with another function, so Im putting in a nested one... I would prefer to declare a regular function, but as far as I know there are no nested functions in Erlang (regular named functions). Edwin Fine-2 wrote: > > To create a fun that calls itself, you must realize that you are creating > an > unnamed function. When you write > > fun(X) -> X * 2 end. > > this is compiled to a Fun data type, e.g. #Fun. > > Since the function does not have a name, it cannot refer to itself. > > When you write FunVar = fun(X) -> X * 2 end, the function is bound to the > variable FunVar. Because the binding takes place *after* the fun is > created, > the fun cannot refer to the variable FunVar within its definition. > > So how is it done? You have to pass the variable to the function so that > it > "knows" what to call: > > FunVar = > fun(MySelf) -> > ... > MySelf(). > > Then when you call it, you call FunVar(FunVar). Looks strange but it > works. > > Example: Writing a simple generate and fold function using only a fun() > variable. > > 9> GenFold = > fun(0, Acc, _) -> > Acc; > (X, Acc, Fun) -> > Fun(X - 1, [X|Acc], Fun) > end. > #Fun > 10> GenFold(10, [], > GenFold). > [1,2,3,4,5,6,7,8,9,10] > 11> > > Or a for loop: > > 22> For = > fun(Max, Max, ExecFun, _) -> > ok; > (N, Max, ExecFun, Next) -> > ExecFun(N), > Next(N + 1, Max, ExecFun, Next) > end. > #Fun > 23> For(0,10,fun(I) -> io:format("~B ", [I]) end, > For). > > 0 1 2 3 4 5 6 7 8 9 ok > 24> > > Stuff like this is described in Joe Armstrong's Erlang book. > > Hope this helps. > > On Sat, Oct 4, 2008 at 11:19 PM, deepblue_other wrote: > >> >> hello >> I have this going on >> >> FunVar = >> fun() -> >> ... >> FunVar() >> end. >> >> so the compiler is complaining that FunVar is unbound at the place where >> its >> being used inside fun(); this makes sense, however Im wondering how to >> make >> this into a recursive function since there's no name to reference the >> function with. >> >> thanks >> -- >> View this message in context: >> http://www.nabble.com/recursive-fun%28%29-tp19820386p19820386.html >> Sent from the Erlang Questions mailing list archive at Nabble.com. >> >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions >> http://www.erlang.org/mailman/listinfo/erlang-questions >> >> > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > what you have described makes perfect sense thanks -- View this message in context: http://www.nabble.com/recursive-fun%28%29-tp19820386p19825467.html Sent from the Erlang Questions mailing list archive at Nabble.com. From exta7 Sun Oct 5 17:38:31 2008 From: exta7 (Zvi) Date: Sun, 5 Oct 2008 08:38:31 -0700 (PDT) Subject: [erlang-questions] re cursive fun() In-Reply-To: <19820386.post@talk.nabble.com> References: <19820386.post@talk.nabble.com> Message-ID: <19825781.post@talk.nabble.com> Otherwise, than passing the Fun as argument to itself, one can implement recursive functions, using code, like this: fact(0) -> 1; fact(N) when N>0 -> {M,F,_A} = element(2,process_info(self(),current_function)), N * {M,F}(N-1). But this doesn't work for funs, if there are was something like: Fact = fun(0) -> 1; (N) when N>0 -> Fun = element(2,process_info(self(),current_fun)), N * Fun(N-1). Zvi deepblue_other wrote: > > hello > I have this going on > > FunVar = > fun() -> > ... > FunVar() > end. > > so the compiler is complaining that FunVar is unbound at the place where > its being used inside fun(); this makes sense, however Im wondering how to > make this into a recursive function since there's no name to reference the > function with. > > thanks > -- View this message in context: http://www.nabble.com/recursive-fun%28%29-tp19820386p19825781.html Sent from the Erlang Questions mailing list archive at Nabble.com. From cktgatb Sun Oct 5 18:07:57 2008 From: cktgatb (deepblue_other) Date: Sun, 5 Oct 2008 09:07:57 -0700 (PDT) Subject: [erlang-questions] re cursive fun() In-Reply-To: <19825781.post@talk.nabble.com> References: <19820386.post@talk.nabble.com> <19825781.post@talk.nabble.com> Message-ID: <19826090.post@talk.nabble.com> so definitely no named nested functions? Zvi wrote: > > Otherwise, than passing the Fun as argument to itself, one can implement > recursive functions, using code, like this: > > fact(0) -> 1; > fact(N) when N>0 -> > {M,F,_A} = element(2,process_info(self(),current_function)), > N * {M,F}(N-1). > > But this doesn't work for funs, if there are was something like: > > Fact = fun(0) -> 1; > (N) when N>0 -> > Fun = element(2,process_info(self(),current_fun)), > N * Fun(N-1). > > Zvi > > > deepblue_other wrote: >> >> hello >> I have this going on >> >> FunVar = >> fun() -> >> ... >> FunVar() >> end. >> >> so the compiler is complaining that FunVar is unbound at the place where >> its being used inside fun(); this makes sense, however Im wondering how >> to make this into a recursive function since there's no name to reference >> the function with. >> >> thanks >> > > -- View this message in context: http://www.nabble.com/recursive-fun%28%29-tp19820386p19826090.html Sent from the Erlang Questions mailing list archive at Nabble.com. From cktgatb Sun Oct 5 18:07:08 2008 From: cktgatb (deepblue_other) Date: Sun, 5 Oct 2008 09:07:08 -0700 (PDT) Subject: [erlang-questions] tcp sockets - not clear Message-ID: <19826070.post@talk.nabble.com> hello everyone Im building a system with a Flash front-end and an Erlang back-end and have some confusion in a case where there is a single socket on the back-end per user (per single socket on the front-end). I want to have multiple independent objects on the front-end send messages to the back-end, but am not sure how the simultaneous transmission would be handled. This probably stems from my somewhat clowdly understanding of TCP. Say there are 3 objects that initiate a send() method on the front-end (almost at the same time) and send a semi large message each to the back-end. Each message would be ID'd by the front-end so that when received back it can be routed to the appropriate callback. Is this possible? since the packets are being assembled in the {tcp, Socket, Data} pattern match, peace by peace, would the correct peaces of the individual messages be stiched together? (doesnt seem like they would). if that wont work then I would just have the serialize the sending/receiving, which is not too horrible... thanks -- View this message in context: http://www.nabble.com/tcp-sockets---not-clear-tp19826070p19826070.html Sent from the Erlang Questions mailing list archive at Nabble.com. From saleyn Sun Oct 5 18:14:52 2008 From: saleyn (Serge Aleynikov) Date: Sun, 05 Oct 2008 12:14:52 -0400 Subject: [erlang-questions] jinterface In-Reply-To: <95be1d3b0810041102r5fbfd2f6t5e54c2551926e226@mail.gmail.com> References: <6C2A5378-5BDE-4FF9-B2AF-790D1F78330B@kallisys.net> <48E7730B.3090506@gmail.com> <95be1d3b0810041102r5fbfd2f6t5e54c2551926e226@mail.gmail.com> Message-ID: <48E8E7FC.9040405@gmail.com> While we are on the subject, I was looking at the hierarchy of classes in jinterface/otp.net and have some design questions. 1. OtpSelf and OtpNode inherit from OtpLocalNode. Only OtpNode implements OtpMbox support. Consequently OtpSelf can't create a mailbox and use its send/receive functions. It looks like it would make more sense if OtpSelf inherited from OtpNode, so that if would have access to all mbox / registerName / whereis goodies. 2. OtpCookedConnection and OtpConnection inherit from AbstractConnection, but only OtpConnection has sendRPC/receiveRPC and only OtpCookedConnection keeps track of established links. It would make more sense if OtpConnection inherited from OtpCookedConnection so that OtpNode can do sendRPC/receiveRPC calls and also be aware of link management offered by OtpCooked Connection. Perhaps I am missing something but it's not clear from this class hierarchy what the intent of the designer was... Serge Vlad Dumitrescu wrote: > On Sat, Oct 4, 2008 at 15:43, Serge Aleynikov wrote: >> Actually I see what's missing in Java/OTP.NET implementation. These >> features are documented here: >> http://www.erlang.org/doc/apps/erts/erl_dist_protocol.html#9.7 > > Even if those features were implemented, the Java VM is still not the > BEAM VM, so it wouldn't be te same anyway. The impedance mismatch > between the two runtime models is too large to integrate them > seamlessly. > >> Actually, my overall goal was to establish the reverse - monitor an Erlang process >> from a .NET client (or java), where the client implements a UI application that >> establishes subscription with a process for receiving events of some sort, and >> tries to reestablish subscription if it detects that the remote process died. > > Then you are in luck, because it can be done! Start a process that > will do the monitoring and let it forward the messages to the Java > side. This proxying technique can be applied in many other contexts, > too. For example, for the io:format problem, you can start a io server > that works as a proxy for the missing one on the Java side. But you > may find soon that you will prefer to move more and more functionality > on the Erlang side and use Java just as a presentation layer. > > best regards, > Vlad > From cktgatb Sun Oct 5 18:39:41 2008 From: cktgatb (deepblue_other) Date: Sun, 5 Oct 2008 09:39:41 -0700 (PDT) Subject: [erlang-questions] wierd "function not used" problem - code included Message-ID: <19826465.post@talk.nabble.com> Hello, its me again... so I've been having this problem for days, with the bellow code. Most of it is straight out of the "Programming Erlang" book from Joe Armstrong... however when Im compiling it its telling me that the function data_process/1 is not being used, gives me a warning, but then still compiles. however when Im sending data from a client side via TCP ofcourse it exits on me because there's nothing to process the message... I HAVE NO IDEA WHAT'S WRONG WITH IT. I've read up on all the spawn_link() definitions and as far as I can tell Im using it correctly... the PiD that spawn_link() returns is being returned so it executes successfully. please help out, its stalling my project progress. thanks -module(tcp_manager). %API-------------------------------------------- -export([start/1]). %----------------------------------------------- start(Port) -> {ok, ListeningSocket} = gen_tcp:listen( Port, [ binary, %receive data in binary form {packet , 0}, {reuseaddr, true}, %hybrid - active for only one message %it auto-receives one message after which it blocks %has to be set to active-once again to receive the next message {active , once} ] ), accept_connection(ListeningSocket). %----------------------------------------------- accept_connection(ListeningSocket) -> io:format("waiting to accept~n"), {ok, Socket} = gen_tcp:accept(ListeningSocket), io:format("Socket is:~p~n", [Socket]), %----------------------------------------------- Listen_for_errors = fun() -> io:format("listening started~n"), receive {'EXIT', Pid, Why} -> io:format("~p exited because:~p", [Pid,Why]); Other -> io:format("Other:~p~n", [Other]) end end, Listen_for_errors(), %----------------------------------------------- Handler_process = spawn_link(?MODULE, data_process, [Socket]), %,[]]), io:format("handlers process ID:~p", [Handler_process]). accept_connection(ListeningSocket). %----------------------------------------------- data_process( Socket, DataSoFar) -> io:format("responder_loop() entered~n"), receive {tcp, Socket, Data} -> %Source_ip = inet:peername(Socket), %io:format("*~p - data coming in:~p~n",[Source_ip,Data]), io:format("works - Data:~p~n", [Data]), %has to be done, since its an active-once socket inet:setopts( Socket, [{active,once}] ), data_process( Socket, %append the new binary fragment to what has been received so far [Data | DataSoFar] ); {tcp_closed, Socket} -> io:format("*client socket closed~n"); %reverse because data has been appended to the head of the list as it was coming in list_to_binary(lists:reverse(SoFar)); Other -> io:format("undefined message came in:~p", [Other]) end. %----------------------------------------------- -- View this message in context: http://www.nabble.com/wierd-%22function-not-used%22-problem---code-included-tp19826465p19826465.html Sent from the Erlang Questions mailing list archive at Nabble.com. From alpar Sun Oct 5 18:52:30 2008 From: alpar (=?ISO-8859-1?Q?Alp=E1r_J=FCttner?=) Date: Sun, 05 Oct 2008 17:52:30 +0100 Subject: [erlang-questions] re cursive fun() In-Reply-To: <19826090.post@talk.nabble.com> References: <19820386.post@talk.nabble.com> <19825781.post@talk.nabble.com> <19826090.post@talk.nabble.com> Message-ID: <1223225550.23038.25.camel@piko.site> You may do a trick like this: 1> Fact = fun(0) -> 1; (N) -> Fun=get(fact), N*Fun(N-1) end. #Fun 2> put(fact,Fact). undefined 3> Fact(5). 120 Regards, Alpar On Sun, 2008-10-05 at 09:07 -0700, deepblue_other wrote: > so definitely no named nested functions? > > Zvi wrote: > > > > Otherwise, than passing the Fun as argument to itself, one can implement > > recursive functions, using code, like this: > > > > fact(0) -> 1; > > fact(N) when N>0 -> > > {M,F,_A} = element(2,process_info(self(),current_function)), > > N * {M,F}(N-1). > > > > But this doesn't work for funs, if there are was something like: > > > > Fact = fun(0) -> 1; > > (N) when N>0 -> > > Fun = element(2,process_info(self(),current_fun)), > > N * Fun(N-1). > > > > Zvi > > > > > > deepblue_other wrote: > >> > >> hello > >> I have this going on > >> > >> FunVar = > >> fun() -> > >> ... > >> FunVar() > >> end. > >> > >> so the compiler is complaining that FunVar is unbound at the place where > >> its being used inside fun(); this makes sense, however Im wondering how > >> to make this into a recursive function since there's no name to reference > >> the function with. > >> > >> thanks > >> > > > > > From cktgatb Sun Oct 5 18:54:32 2008 From: cktgatb (deepblue_other) Date: Sun, 5 Oct 2008 09:54:32 -0700 (PDT) Subject: [erlang-questions] wierd "function not used" problem - code included In-Reply-To: <19826465.post@talk.nabble.com> References: <19826465.post@talk.nabble.com> Message-ID: <19826635.post@talk.nabble.com> this version that I pasted here is data_process/2 and in spawn_link() Im using data_process/1, but thats just an error that i made when pasting the code... Im compiling with: spawn_link(?MODULE, data_process,[Socket,[]]), so the aritiy is correct deepblue_other wrote: > > Hello, its me again... > so I've been having this problem for days, with the bellow code. Most of > it is straight out of the "Programming Erlang" book from Joe Armstrong... > however when Im compiling it its telling me that the function > data_process/1 is not being used, gives me a warning, but then still > compiles. however when Im sending data from a client side via TCP ofcourse > it exits on me because there's nothing to process the message... > > I HAVE NO IDEA WHAT'S WRONG WITH IT. > I've read up on all the spawn_link() definitions and as far as I can tell > Im using it correctly... the PiD that spawn_link() returns is being > returned so it executes successfully. > please help out, its stalling my project progress. > thanks > > > -module(tcp_manager). > %API-------------------------------------------- > -export([start/1]). > %----------------------------------------------- > start(Port) -> > {ok, ListeningSocket} = > gen_tcp:listen( Port, [ binary, %receive data in binary form > {packet , 0}, > {reuseaddr, true}, > %hybrid - active for only one > message > %it auto-receives one message after > which it blocks > %has to be set to active-once again > to receive the next message > {active , once} ] ), > accept_connection(ListeningSocket). > %----------------------------------------------- > accept_connection(ListeningSocket) -> > > io:format("waiting to accept~n"), > {ok, Socket} = gen_tcp:accept(ListeningSocket), > io:format("Socket is:~p~n", [Socket]), > > %----------------------------------------------- > Listen_for_errors = > fun() -> > io:format("listening started~n"), > receive > {'EXIT', Pid, Why} -> > io:format("~p exited because:~p", [Pid,Why]); > Other -> > io:format("Other:~p~n", [Other]) > end > end, > Listen_for_errors(), > %----------------------------------------------- > > Handler_process = spawn_link(?MODULE, data_process, [Socket]), %,[]]), > io:format("handlers process ID:~p", [Handler_process]). > > accept_connection(ListeningSocket). > %----------------------------------------------- > data_process( Socket, DataSoFar) -> > io:format("responder_loop() entered~n"), > > receive > {tcp, Socket, Data} -> > %Source_ip = inet:peername(Socket), > %io:format("*~p - data coming in:~p~n",[Source_ip,Data]), > io:format("works - Data:~p~n", [Data]), > %has to be done, since its an active-once socket > inet:setopts( Socket, [{active,once}] ), > data_process( Socket, > %append the new binary fragment to what > has been received so far > [Data | DataSoFar] ); > > {tcp_closed, Socket} -> > io:format("*client socket closed~n"); > %reverse because data has been appended to the head of the > list as it was coming in > list_to_binary(lists:reverse(SoFar)); > Other -> > io:format("undefined message came in:~p", [Other]) > end. > %----------------------------------------------- > -- View this message in context: http://www.nabble.com/wierd-%22function-not-used%22-problem---code-included-tp19826465p19826635.html Sent from the Erlang Questions mailing list archive at Nabble.com. From michael.regen Sun Oct 5 19:04:12 2008 From: michael.regen (Michael Regen) Date: Sun, 5 Oct 2008 19:04:12 +0200 Subject: [erlang-questions] How to build Erlang with libcmt (/MT) under windows? Message-ID: <9b59d0270810051004u391f464k112d5175573a95f4@mail.gmail.com> Hi, Does anyone a little bit more experienced with the Erlang build mechanism know how to compile and link Erlang with libcmt instead of msvcrt? The default mechanism builds Erlang with the /MD switch which means the C standard libraries are accessed as threaded dll MSVCR??.DLL. This also means you cannot simply copy Erlang to another computer as long as the correct C runtime is not installed there. I am trying to figure out how to statically bind the libcmt library. Normally you do this by using the /MT switch. So far I tried to change the erts\etc\win32\cygwin_tools\vc\cc.sh and ld.sh scripts but with no good effects. I always get the usual error messages like if you mix libraries compiled with different switches. In cc.sh setting MD_FORCED=true MD=-MT and in ld.sh STDLIB=LIBCMT.LIB just leads me to: LIBCMT.LIB(dosmap.obj) : error LNK2005: __dosmaperr already defined in dosmap.o Creating library c:/dev/erlang/ErlangOTP/otp_src_R12B-4/bin/win32/erl_dll.lib and object c:/dev/erlang/ErlangOTP/otp_src_R12B-4/bin/win32/erl_dll.exp c:/dev/erlang/ErlangOTP/otp_src_R12B-4/bin/win32/beam.smp.dll : fatal error LNK1169: one or more multiply defined symbols found Thank you! Regards, Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081005/77845602/attachment.html From michael.regen Sun Oct 5 19:04:12 2008 From: michael.regen (Michael Regen) Date: Sun, 5 Oct 2008 19:04:12 +0200 Subject: [erlang-questions] How to build Erlang with libcmt (/MT) under windows? Message-ID: <9b59d0270810051004u391f464k112d5175573a95f4@mail.gmail.com> Hi, Does anyone a little bit more experienced with the Erlang build mechanism know how to compile and link Erlang with libcmt instead of msvcrt? The default mechanism builds Erlang with the /MD switch which means the C standard libraries are accessed as threaded dll MSVCR??.DLL. This also means you cannot simply copy Erlang to another computer as long as the correct C runtime is not installed there. I am trying to figure out how to statically bind the libcmt library. Normally you do this by using the /MT switch. So far I tried to change the erts\etc\win32\cygwin_tools\vc\cc.sh and ld.sh scripts but with no good effects. I always get the usual error messages like if you mix libraries compiled with different switches. In cc.sh setting MD_FORCED=true MD=-MT and in ld.sh STDLIB=LIBCMT.LIB just leads me to: LIBCMT.LIB(dosmap.obj) : error LNK2005: __dosmaperr already defined in dosmap.o Creating library c:/dev/erlang/ErlangOTP/otp_src_R12B-4/bin/win32/erl_dll.lib and object c:/dev/erlang/ErlangOTP/otp_src_R12B-4/bin/win32/erl_dll.exp c:/dev/erlang/ErlangOTP/otp_src_R12B-4/bin/win32/beam.smp.dll : fatal error LNK1169: one or more multiply defined symbols found Thank you! Regards, Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081005/77845602/attachment-0003.html From oscar Sun Oct 5 19:39:42 2008 From: oscar (=?utf-8?Q?Oscar_Hellstr=C3=B6m?=) Date: Sun, 5 Oct 2008 18:39:42 +0100 (BST) Subject: [erlang-questions] wierd "function not used" problem - code included In-Reply-To: <24151217.5861223228208675.JavaMail.root@zimbra> Message-ID: <33112579.5881223228382303.JavaMail.root@zimbra> Hi, Calling spawn_link(Module, Function, Args) will call Module:Function(Args) as a fully qualified call. Therefore this Function has to be exported. Best regards ----- Original Message ----- From: "deepblue_other" To: erlang-questions Sent: Sunday, 5 October, 2008 9:39:41 AM GMT -08:00 US/Canada Pacific Subject: [erlang-questions] wierd "function not used" problem - code included Hello, its me again... so I've been having this problem for days, with the bellow code. Most of it is straight out of the "Programming Erlang" book from Joe Armstrong... however when Im compiling it its telling me that the function data_process/1 is not being used, gives me a warning, but then still compiles. however when Im sending data from a client side via TCP ofcourse it exits on me because there's nothing to process the message... I HAVE NO IDEA WHAT'S WRONG WITH IT. I've read up on all the spawn_link() definitions and as far as I can tell Im using it correctly... the PiD that spawn_link() returns is being returned so it executes successfully. please help out, its stalling my project progress. thanks -module(tcp_manager). %API-------------------------------------------- -export([start/1]). %----------------------------------------------- start(Port) -> {ok, ListeningSocket} = gen_tcp:listen( Port, [ binary, %receive data in binary form {packet , 0}, {reuseaddr, true}, %hybrid - active for only one message %it auto-receives one message after which it blocks %has to be set to active-once again to receive the next message {active , once} ] ), accept_connection(ListeningSocket). %----------------------------------------------- accept_connection(ListeningSocket) -> io:format("waiting to accept~n"), {ok, Socket} = gen_tcp:accept(ListeningSocket), io:format("Socket is:~p~n", [Socket]), %----------------------------------------------- Listen_for_errors = fun() -> io:format("listening started~n"), receive {'EXIT', Pid, Why} -> io:format("~p exited because:~p", [Pid,Why]); Other -> io:format("Other:~p~n", [Other]) end end, Listen_for_errors(), %----------------------------------------------- Handler_process = spawn_link(?MODULE, data_process, [Socket]), %,[]]), io:format("handlers process ID:~p", [Handler_process]). accept_connection(ListeningSocket). %----------------------------------------------- data_process( Socket, DataSoFar) -> io:format("responder_loop() entered~n"), receive {tcp, Socket, Data} -> %Source_ip = inet:peername(Socket), %io:format("*~p - data coming in:~p~n",[Source_ip,Data]), io:format("works - Data:~p~n", [Data]), %has to be done, since its an active-once socket inet:setopts( Socket, [{active,once}] ), data_process( Socket, %append the new binary fragment to what has been received so far [Data | DataSoFar] ); {tcp_closed, Socket} -> io:format("*client socket closed~n"); %reverse because data has been appended to the head of the list as it was coming in list_to_binary(lists:reverse(SoFar)); Other -> io:format("undefined message came in:~p", [Other]) end. %----------------------------------------------- -- View this message in context: http://www.nabble.com/wierd-%22function-not-used%22-problem---code-included-tp19826465p19826465.html Sent from the Erlang Questions mailing list archive at Nabble.com. _______________________________________________ erlang-questions mailing list erlang-questions http://www.erlang.org/mailman/listinfo/erlang-questions -- Oscar Hellstr?m, oscar Phone: +44 (0)798 45 44 773 Mobile: +44 (0)207 65 50 337 Web: http://www.erlang-consulting.com From rvirding Sun Oct 5 20:00:56 2008 From: rvirding (Robert Virding) Date: Sun, 5 Oct 2008 20:00:56 +0200 Subject: [erlang-questions] wierd "function not used" problem - code included In-Reply-To: <19826465.post@talk.nabble.com> References: <19826465.post@talk.nabble.com> Message-ID: <3dbc6d1c0810051100h7d746760vd6ff1b3c43937b08@mail.gmail.com> data_process/1 is never directly called so the warning is correct. However, to be spawn in that way it must be explicitly exported, that is why you get a runtime error. Try exporting data_process/1 or changing the spawn to: spawn_link(fun () -> data_process(Socket, []) end), Anyway it should be data_process/2 as there is no data_process/1 defined. Robert 2008/10/5 deepblue_other > > Hello, its me again... > so I've been having this problem for days, with the bellow code. Most of it > is straight out of the "Programming Erlang" book from Joe Armstrong... > however when Im compiling it its telling me that the function > data_process/1 > is not being used, gives me a warning, but then still compiles. however > when > Im sending data from a client side via TCP ofcourse it exits on me because > there's nothing to process the message... > > I HAVE NO IDEA WHAT'S WRONG WITH IT. > I've read up on all the spawn_link() definitions and as far as I can tell > Im > using it correctly... the PiD that spawn_link() returns is being returned > so > it executes successfully. > please help out, its stalling my project progress. > thanks > > > -module(tcp_manager). > %API-------------------------------------------- > -export([start/1]). > %----------------------------------------------- > start(Port) -> > {ok, ListeningSocket} = > gen_tcp:listen( Port, [ binary, %receive data in binary form > {packet , 0}, > {reuseaddr, true}, > %hybrid - active for only one message > %it auto-receives one message after > which it blocks > %has to be set to active-once again to > receive the next message > {active , once} ] ), > accept_connection(ListeningSocket). > %----------------------------------------------- > accept_connection(ListeningSocket) -> > > io:format("waiting to accept~n"), > {ok, Socket} = gen_tcp:accept(ListeningSocket), > io:format("Socket is:~p~n", [Socket]), > > %----------------------------------------------- > Listen_for_errors = > fun() -> > io:format("listening started~n"), > receive > {'EXIT', Pid, Why} -> > io:format("~p exited because:~p", [Pid,Why]); > Other -> > io:format("Other:~p~n", [Other]) > end > end, > Listen_for_errors(), > %----------------------------------------------- > > Handler_process = spawn_link(?MODULE, data_process, [Socket]), %,[]]), > io:format("handlers process ID:~p", [Handler_process]). > > accept_connection(ListeningSocket). > %----------------------------------------------- > data_process( Socket, DataSoFar) -> > io:format("responder_loop() entered~n"), > > receive > {tcp, Socket, Data} -> > %Source_ip = inet:peername(Socket), > %io:format("*~p - data coming in:~p~n",[Source_ip,Data]), > io:format("works - Data:~p~n", [Data]), > %has to be done, since its an active-once socket > inet:setopts( Socket, [{active,once}] ), > data_process( Socket, > %append the new binary fragment to what has > been received so far > [Data | DataSoFar] ); > > {tcp_closed, Socket} -> > io:format("*client socket closed~n"); > %reverse because data has been appended to the head of the list > as it was coming in > list_to_binary(lists:reverse(SoFar)); > Other -> > io:format("undefined message came in:~p", [Other]) > end. > %----------------------------------------------- > -- > View this message in context: > http://www.nabble.com/wierd-%22function-not-used%22-problem---code-included-tp19826465p19826465.html > Sent from the Erlang Questions mailing list archive at Nabble.com. > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081005/bed8d8f7/attachment.html From cktgatb Sun Oct 5 20:34:30 2008 From: cktgatb (deepblue_other) Date: Sun, 5 Oct 2008 11:34:30 -0700 (PDT) Subject: [erlang-questions] wierd "function not used" problem - code included In-Reply-To: <19826465.post@talk.nabble.com> References: <19826465.post@talk.nabble.com> Message-ID: <19827659.post@talk.nabble.com> hmmm sorry, just a moment deepblue_other wrote: > > Hello, its me again... > so I've been having this problem for days, with the bellow code. Most of > it is straight out of the "Programming Erlang" book from Joe Armstrong... > however when Im compiling it its telling me that the function > data_process/1 is not being used, gives me a warning, but then still > compiles. however when Im sending data from a client side via TCP ofcourse > it exits on me because there's nothing to process the message... > > I HAVE NO IDEA WHAT'S WRONG WITH IT. > I've read up on all the spawn_link() definitions and as far as I can tell > Im using it correctly... the PiD that spawn_link() returns is being > returned so it executes successfully. > please help out, its stalling my project progress. > thanks > > > -module(tcp_manager). > %API-------------------------------------------- > -export([start/1]). > %----------------------------------------------- > start(Port) -> > {ok, ListeningSocket} = > gen_tcp:listen( Port, [ binary, %receive data in binary form > {packet , 0}, > {reuseaddr, true}, > %hybrid - active for only one > message > %it auto-receives one message after > which it blocks > %has to be set to active-once again > to receive the next message > {active , once} ] ), > accept_connection(ListeningSocket). > %----------------------------------------------- > accept_connection(ListeningSocket) -> > > io:format("waiting to accept~n"), > {ok, Socket} = gen_tcp:accept(ListeningSocket), > io:format("Socket is:~p~n", [Socket]), > > %----------------------------------------------- > Listen_for_errors = > fun() -> > io:format("listening started~n"), > receive > {'EXIT', Pid, Why} -> > io:format("~p exited because:~p", [Pid,Why]); > Other -> > io:format("Other:~p~n", [Other]) > end > end, > Listen_for_errors(), > %----------------------------------------------- > > Handler_process = spawn_link(?MODULE, data_process, [Socket]), %,[]]), > io:format("handlers process ID:~p", [Handler_process]). > > accept_connection(ListeningSocket). > %----------------------------------------------- > data_process( Socket, DataSoFar) -> > io:format("responder_loop() entered~n"), > > receive > {tcp, Socket, Data} -> > %Source_ip = inet:peername(Socket), > %io:format("*~p - data coming in:~p~n",[Source_ip,Data]), > io:format("works - Data:~p~n", [Data]), > %has to be done, since its an active-once socket > inet:setopts( Socket, [{active,once}] ), > data_process( Socket, > %append the new binary fragment to what > has been received so far > [Data | DataSoFar] ); > > {tcp_closed, Socket} -> > io:format("*client socket closed~n"); > %reverse because data has been appended to the head of the > list as it was coming in > list_to_binary(lists:reverse(SoFar)); > Other -> > io:format("undefined message came in:~p", [Other]) > end. > %----------------------------------------------- > -- View this message in context: http://www.nabble.com/wierd-%22function-not-used%22-problem---code-included-tp19826465p19827659.html Sent from the Erlang Questions mailing list archive at Nabble.com. From erlang-questions_efine Sun Oct 5 20:25:47 2008 From: erlang-questions_efine (Edwin Fine) Date: Sun, 5 Oct 2008 11:25:47 -0700 (PDT) Subject: [erlang-questions] wierd "function not used" problem - code included In-Reply-To: <19826635.post@talk.nabble.com> References: <19826465.post@talk.nabble.com> <19826635.post@talk.nabble.com> Message-ID: <19827568.post@talk.nabble.com> Your code as pasted here does not compile, even after correcting the spawn_link arity. There are syntax errors. Please post a version that compiles. -- View this message in context: http://www.nabble.com/wierd-%22function-not-used%22-problem---code-included-tp19826465p19827568.html Sent from the Erlang Questions mailing list archive at Nabble.com. From cktgatb Sun Oct 5 20:40:18 2008 From: cktgatb (deepblue_other) Date: Sun, 5 Oct 2008 11:40:18 -0700 (PDT) Subject: [erlang-questions] wierd "function not used" problem - code included In-Reply-To: <19827696.post@talk.nabble.com> References: <19826465.post@talk.nabble.com> <19827659.post@talk.nabble.com> <19827696.post@talk.nabble.com> Message-ID: <19827720.post@talk.nabble.com> there was a tiny error in the last one, and I put the correct arity in spawn_link() this should compile thanks -module(tcp_manager). %API-------------------------------------------- -export([start/1]). %----------------------------------------------- start(Port) -> {ok, ListeningSocket} = gen_tcp:listen( Port, [ binary, %receive data in binary form {packet , 0}, {reuseaddr, true}, {active , once} ] ), accept_connection(ListeningSocket). %----------------------------------------------- accept_connection(ListeningSocket) -> io:format("waiting to accept~n"), {ok, Socket} = gen_tcp:accept(ListeningSocket), io:format("Socket is:~p~n", [Socket]), %----------------------------------------------- Listen_for_errors = fun() -> io:format("listening started~n"), receive {'EXIT', Pid, Why} -> io:format("~p exited because:~p", [Pid,Why]); Other -> io:format("Other:~p~n", [Other]) end end, Listen_for_errors(), %----------------------------------------------- Handler_process = spawn_link(?MODULE, data_process, [Socket, []]), io:format("handlers process ID:~p", [Handler_process]). %----------------------------------------------- data_process( Socket, DataSoFar) -> io:format("responder_loop() entered~n"), receive {tcp, Socket, Data} -> io:format("works - Data:~p~n", [Data]), inet:setopts( Socket, [{active,once}] ), data_process( Socket, [Data | DataSoFar] ); {tcp_closed, Socket} -> io:format("*client socket closed~n"); Other -> io:format("undefined message came in:~p", [Other]) end. %----------------------------------------------- deepblue_other wrote: > > here you go, this should compile > sorry about that > thanks > > -module(tcp_manager). > %API-------------------------------------------- > -export([start/1]). > %----------------------------------------------- > start(Port) -> > {ok, ListeningSocket} = > gen_tcp:listen( Port, [ binary, %receive data in binary form > {packet , 0}, > {reuseaddr, true}, > {active , once} ] ), > accept_connection(ListeningSocket). > %----------------------------------------------- > accept_connection(ListeningSocket) -> > > io:format("waiting to accept~n"), > {ok, Socket} = gen_tcp:accept(ListeningSocket), > io:format("Socket is:~p~n", [Socket]), > > %----------------------------------------------- > Listen_for_errors = > fun() -> > io:format("listening started~n"), > receive > {'EXIT', Pid, Why} -> > io:format("~p exited because:~p", [Pid,Why]); > Other -> > io:format("Other:~p~n", [Other]) > end > end, > Listen_for_errors(), > %----------------------------------------------- > > Handler_process = spawn_link(?MODULE, data_process, [Socket]), %,[]]), > io:format("handlers process ID:~p", [Handler_process]). > %----------------------------------------------- > data_process( Socket, DataSoFar) -> > io:format("responder_loop() entered~n"), > > receive > {tcp, Socket, Data} -> > io:format("works - Data:~p~n", [Data]), > inet:setopts( Socket, [{active,once}] ), > data_process( Socket, > [Data | DataSoFar] ); > > {tcp_closed, Socket} -> > io:format("*client socket closed~n"); > Other -> > io:format("undefined message came in:~p", [Other]) > end. > %----------------------------------------------- > > deepblue_other wrote: >> >> hmmm >> sorry, just a moment >> >> deepblue_other wrote: >>> >>> Hello, its me again... >>> so I've been having this problem for days, with the bellow code. Most of >>> it is straight out of the "Programming Erlang" book from Joe >>> Armstrong... however when Im compiling it its telling me that the >>> function data_process/1 is not being used, gives me a warning, but then >>> still compiles. however when Im sending data from a client side via TCP >>> ofcourse it exits on me because there's nothing to process the >>> message... >>> >>> I HAVE NO IDEA WHAT'S WRONG WITH IT. >>> I've read up on all the spawn_link() definitions and as far as I can >>> tell Im using it correctly... the PiD that spawn_link() returns is being >>> returned so it executes successfully. >>> please help out, its stalling my project progress. >>> thanks >>> >>> >>> -module(tcp_manager). >>> %API-------------------------------------------- >>> -export([start/1]). >>> %----------------------------------------------- >>> start(Port) -> >>> {ok, ListeningSocket} = >>> gen_tcp:listen( Port, [ binary, %receive data in binary form >>> {packet , 0}, >>> {reuseaddr, true}, >>> %hybrid - active for only one >>> message >>> %it auto-receives one message >>> after which it blocks >>> %has to be set to active-once >>> again to receive the next message >>> {active , once} ] ), >>> accept_connection(ListeningSocket). >>> %----------------------------------------------- >>> accept_connection(ListeningSocket) -> >>> >>> io:format("waiting to accept~n"), >>> {ok, Socket} = gen_tcp:accept(ListeningSocket), >>> io:format("Socket is:~p~n", [Socket]), >>> >>> %----------------------------------------------- >>> Listen_for_errors = >>> fun() -> >>> io:format("listening started~n"), >>> receive >>> {'EXIT', Pid, Why} -> >>> io:format("~p exited because:~p", [Pid,Why]); >>> Other -> >>> io:format("Other:~p~n", [Other]) >>> end >>> end, >>> Listen_for_errors(), >>> %----------------------------------------------- >>> >>> Handler_process = spawn_link(?MODULE, data_process, [Socket]), >>> %,[]]), >>> io:format("handlers process ID:~p", [Handler_process]). >>> >>> accept_connection(ListeningSocket). >>> %----------------------------------------------- >>> data_process( Socket, DataSoFar) -> >>> io:format("responder_loop() entered~n"), >>> >>> receive >>> {tcp, Socket, Data} -> >>> %Source_ip = inet:peername(Socket), >>> %io:format("*~p - data coming in:~p~n",[Source_ip,Data]), >>> io:format("works - Data:~p~n", [Data]), >>> %has to be done, since its an active-once socket >>> inet:setopts( Socket, [{active,once}] ), >>> data_process( Socket, >>> %append the new binary fragment to what >>> has been received so far >>> [Data | DataSoFar] ); >>> >>> {tcp_closed, Socket} -> >>> io:format("*client socket closed~n"); >>> %reverse because data has been appended to the head of the >>> list as it was coming in >>> list_to_binary(lists:reverse(SoFar)); >>> Other -> >>> io:format("undefined message came in:~p", [Other]) >>> end. >>> %----------------------------------------------- >>> >> >> > > -- View this message in context: http://www.nabble.com/wierd-%22function-not-used%22-problem---code-included-tp19826465p19827720.html Sent from the Erlang Questions mailing list archive at Nabble.com. From cktgatb Sun Oct 5 20:38:14 2008 From: cktgatb (deepblue_other) Date: Sun, 5 Oct 2008 11:38:14 -0700 (PDT) Subject: [erlang-questions] wierd "function not used" problem - code included In-Reply-To: <19827659.post@talk.nabble.com> References: <19826465.post@talk.nabble.com> <19827659.post@talk.nabble.com> Message-ID: <19827696.post@talk.nabble.com> here you go, this should compile sorry about that thanks -module(tcp_manager). %API-------------------------------------------- -export([start/1]). %----------------------------------------------- start(Port) -> {ok, ListeningSocket} = gen_tcp:listen( Port, [ binary, %receive data in binary form {packet , 0}, {reuseaddr, true}, {active , once} ] ), accept_connection(ListeningSocket). %----------------------------------------------- accept_connection(ListeningSocket) -> io:format("waiting to accept~n"), {ok, Socket} = gen_tcp:accept(ListeningSocket), io:format("Socket is:~p~n", [Socket]), %----------------------------------------------- Listen_for_errors = fun() -> io:format("listening started~n"), receive {'EXIT', Pid, Why} -> io:format("~p exited because:~p", [Pid,Why]); Other -> io:format("Other:~p~n", [Other]) end end, Listen_for_errors(), %----------------------------------------------- Handler_process = spawn_link(?MODULE, data_process, [Socket]), %,[]]), io:format("handlers process ID:~p", [Handler_process]). %----------------------------------------------- data_process( Socket, DataSoFar) -> io:format("responder_loop() entered~n"), receive {tcp, Socket, Data} -> io:format("works - Data:~p~n", [Data]), inet:setopts( Socket, [{active,once}] ), data_process( Socket, [Data | DataSoFar] ); {tcp_closed, Socket} -> io:format("*client socket closed~n"); Other -> io:format("undefined message came in:~p", [Other]) end. %----------------------------------------------- deepblue_other wrote: > > hmmm > sorry, just a moment > > deepblue_other wrote: >> >> Hello, its me again... >> so I've been having this problem for days, with the bellow code. Most of >> it is straight out of the "Programming Erlang" book from Joe Armstrong... >> however when Im compiling it its telling me that the function >> data_process/1 is not being used, gives me a warning, but then still >> compiles. however when Im sending data from a client side via TCP >> ofcourse it exits on me because there's nothing to process the message... >> >> I HAVE NO IDEA WHAT'S WRONG WITH IT. >> I've read up on all the spawn_link() definitions and as far as I can tell >> Im using it correctly... the PiD that spawn_link() returns is being >> returned so it executes successfully. >> please help out, its stalling my project progress. >> thanks >> >> >> -module(tcp_manager). >> %API-------------------------------------------- >> -export([start/1]). >> %----------------------------------------------- >> start(Port) -> >> {ok, ListeningSocket} = >> gen_tcp:listen( Port, [ binary, %receive data in binary form >> {packet , 0}, >> {reuseaddr, true}, >> %hybrid - active for only one >> message >> %it auto-receives one message after >> which it blocks >> %has to be set to active-once again >> to receive the next message >> {active , once} ] ), >> accept_connection(ListeningSocket). >> %----------------------------------------------- >> accept_connection(ListeningSocket) -> >> >> io:format("waiting to accept~n"), >> {ok, Socket} = gen_tcp:accept(ListeningSocket), >> io:format("Socket is:~p~n", [Socket]), >> >> %----------------------------------------------- >> Listen_for_errors = >> fun() -> >> io:format("listening started~n"), >> receive >> {'EXIT', Pid, Why} -> >> io:format("~p exited because:~p", [Pid,Why]); >> Other -> >> io:format("Other:~p~n", [Other]) >> end >> end, >> Listen_for_errors(), >> %----------------------------------------------- >> >> Handler_process = spawn_link(?MODULE, data_process, [Socket]), >> %,[]]), >> io:format("handlers process ID:~p", [Handler_process]). >> >> accept_connection(ListeningSocket). >> %----------------------------------------------- >> data_process( Socket, DataSoFar) -> >> io:format("responder_loop() entered~n"), >> >> receive >> {tcp, Socket, Data} -> >> %Source_ip = inet:peername(Socket), >> %io:format("*~p - data coming in:~p~n",[Source_ip,Data]), >> io:format("works - Data:~p~n", [Data]), >> %has to be done, since its an active-once socket >> inet:setopts( Socket, [{active,once}] ), >> data_process( Socket, >> %append the new binary fragment to what >> has been received so far >> [Data | DataSoFar] ); >> >> {tcp_closed, Socket} -> >> io:format("*client socket closed~n"); >> %reverse because data has been appended to the head of the >> list as it was coming in >> list_to_binary(lists:reverse(SoFar)); >> Other -> >> io:format("undefined message came in:~p", [Other]) >> end. >> %----------------------------------------------- >> > > -- View this message in context: http://www.nabble.com/wierd-%22function-not-used%22-problem---code-included-tp19826465p19827696.html Sent from the Erlang Questions mailing list archive at Nabble.com. From fredrik.svahn Sun Oct 5 19:28:51 2008 From: fredrik.svahn (Fredrik Svahn) Date: Sun, 5 Oct 2008 19:28:51 +0200 Subject: [erlang-questions] wierd "function not used" problem - code included In-Reply-To: <19826465.post@talk.nabble.com> References: <19826465.post@talk.nabble.com> Message-ID: Hi, The function given as an argument to spawn/spawn_link must be exported. See e.g. http://erlang.org/doc/getting_started/conc_prog.html#3.1 BR /Fredrik On Sun, Oct 5, 2008 at 6:39 PM, deepblue_other wrote: > > Hello, its me again... > so I've been having this problem for days, with the bellow code. Most of it > is straight out of the "Programming Erlang" book from Joe Armstrong... > however when Im compiling it its telling me that the function > data_process/1 > is not being used, gives me a warning, but then still compiles. however > when > Im sending data from a client side via TCP ofcourse it exits on me because > there's nothing to process the message... > > I HAVE NO IDEA WHAT'S WRONG WITH IT. > I've read up on all the spawn_link() definitions and as far as I can tell > Im > using it correctly... the PiD that spawn_link() returns is being returned > so > it executes successfully. > please help out, its stalling my project progress. > thanks > > > -module(tcp_manager). > %API-------------------------------------------- > -export([start/1]). > %----------------------------------------------- > start(Port) -> > {ok, ListeningSocket} = > gen_tcp:listen( Port, [ binary, %receive data in binary form > {packet , 0}, > {reuseaddr, true}, > %hybrid - active for only one message > %it auto-receives one message after > which it blocks > %has to be set to active-once again to > receive the next message > {active , once} ] ), > accept_connection(ListeningSocket). > %----------------------------------------------- > accept_connection(ListeningSocket) -> > > io:format("waiting to accept~n"), > {ok, Socket} = gen_tcp:accept(ListeningSocket), > io:format("Socket is:~p~n", [Socket]), > > %----------------------------------------------- > Listen_for_errors = > fun() -> > io:format("listening started~n"), > receive > {'EXIT', Pid, Why} -> > io:format("~p exited because:~p", [Pid,Why]); > Other -> > io:format("Other:~p~n", [Other]) > end > end, > Listen_for_errors(), > %----------------------------------------------- > > Handler_process = spawn_link(?MODULE, data_process, [Socket]), %,[]]), > io:format("handlers process ID:~p", [Handler_process]). > > accept_connection(ListeningSocket). > %----------------------------------------------- > data_process( Socket, DataSoFar) -> > io:format("responder_loop() entered~n"), > > receive > {tcp, Socket, Data} -> > %Source_ip = inet:peername(Socket), > %io:format("*~p - data coming in:~p~n",[Source_ip,Data]), > io:format("works - Data:~p~n", [Data]), > %has to be done, since its an active-once socket > inet:setopts( Socket, [{active,once}] ), > data_process( Socket, > %append the new binary fragment to what has > been received so far > [Data | DataSoFar] ); > > {tcp_closed, Socket} -> > io:format("*client socket closed~n"); > %reverse because data has been appended to the head of the list > as it was coming in > list_to_binary(lists:reverse(SoFar)); > Other -> > io:format("undefined message came in:~p", [Other]) > end. > %----------------------------------------------- > -- > View this message in context: > http://www.nabble.com/wierd-%22function-not-used%22-problem---code-included-tp19826465p19826465.html > Sent from the Erlang Questions mailing list archive at Nabble.com. > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081005/c19bb1b5/attachment.html From erlang-questions_efine Sun Oct 5 19:55:29 2008 From: erlang-questions_efine (Edwin Fine) Date: Sun, 5 Oct 2008 13:55:29 -0400 Subject: [erlang-questions] tcp sockets - not clear In-Reply-To: <19826070.post@talk.nabble.com> References: <19826070.post@talk.nabble.com> Message-ID: <6c2563b20810051055r407dda00w3d6b094298bace42@mail.gmail.com> Unless you write it otherwise, I would imagine that each front-end object will get its own independent socket and therefore have its own channel to the back end. On the back end, have a listener that kicks off one Erlang process per new socket to handle the message. Messages in this way will not interfere with each other and you can construct them without fear of them getting mixed up. If you want to see a good example of this, look at the way the listener in the gen_smsc.erl module of the OSERL application ( http://oserl.sourceforge.net) waits for connections, spawns a session process for each connection, and passes off the now-open socket to the spawned process (and makes it the owner of the socket, too - important). -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081005/5f902e01/attachment.html From erlang-questions_efine Sun Oct 5 22:02:02 2008 From: erlang-questions_efine (Edwin Fine) Date: Sun, 5 Oct 2008 13:02:02 -0700 (PDT) Subject: [erlang-questions] wierd "function not used" problem - code included In-Reply-To: <19827720.post@talk.nabble.com> References: <19826465.post@talk.nabble.com> <19827659.post@talk.nabble.com> <19827696.post@talk.nabble.com> <19827720.post@talk.nabble.com> Message-ID: <19828568.post@talk.nabble.com> Well, there are a couple of problems, but the reason why you get that warning is that you have to export a function that you spawn_link to using Module/Func/Args syntax, otherwise you would have to Handler_process = spawn_link(fun() -> data_process(Socket, []) end), The other problem is that your fun Listen_for_errors may as well be inline, i.e. you could change this code: %----------------------------------------------- Listen_for_errors = fun() -> io:format("listening started~n"), receive {'EXIT', Pid, Why} -> io:format("~p exited because:~p", [Pid,Why]); Other -> io:format("Other:~p~n", [Other]) end end, Listen_for_errors(), %----------------------------------------------- Handler_process = spawn_link(?MODULE, data_process, [Socket, []]), To this: %----------------------------------------------- io:format("listening started~n"), receive {'EXIT', Pid, Why} -> io:format("~p exited because:~p", [Pid,Why]); Other -> io:format("Other:~p~n", [Other]) end, %----------------------------------------------- Handler_process = spawn_link(?MODULE, data_process, [Socket, []]), -- View this message in context: http://www.nabble.com/wierd-%22function-not-used%22-problem---code-included-tp19826465p19828568.html Sent from the Erlang Questions mailing list archive at Nabble.com. From aconbere Mon Oct 6 00:15:26 2008 From: aconbere (anders conbere) Date: Sun, 5 Oct 2008 15:15:26 -0700 Subject: [erlang-questions] a little meta-programing help Message-ID: <8ca3fbe80810051515m6b983822re94985aa0b63248c@mail.gmail.com> Today I sat down to try to make working with mochiweb a little cleaner for myself. I wanted a way to specify a list of mappings between url patterns and methods to be called with the matched variables from them. I quickly ran into issues with not being able to create patterns dynamically, and then tried using funs to wrap that functionality but pretty soon I was back at the same mess I started with. This is kind of my "if the world were perfect" module (that doesn't work at all but I hope might show what I was going for). I was hoping folks might help be think up some ways to handle use cases like this. -module(roto_web_routes). -export([ call/1 ]). -define(VIEWS_MODULE, roto_web_views). routes() -> [ url(["version"], version), url(["register"], register), url(["node", NodeName, "messages"], messages), url(["node", NodeName, "messages", Id], message), url(["node", NodeName, "messages"], subscriptions), url(["node", NodeName, "messages", Id], subscriptions) ]. url(Pattern, View) -> {route, Pattern, View, View}. url(Pattern, View, Name) -> {route, Pattern, View, Name}. % should take a request, find the matching url config and pass % the matched variables into the function specified in the url % config for that entry. call(Req) -> Path = string:tokens(Req:get(path), "/"), match_route(Path). match_route(Path) -> %does something fancy with routes() to get to the function % I want to call and call it with the matched variables ok. Thanks! ~ Anders From cktgatb Mon Oct 6 00:55:10 2008 From: cktgatb (deepblue_other) Date: Sun, 5 Oct 2008 15:55:10 -0700 (PDT) Subject: [erlang-questions] wierd "function not used" problem - code included In-Reply-To: <19828568.post@talk.nabble.com> References: <19826465.post@talk.nabble.com> <19827659.post@talk.nabble.com> <19827696.post@talk.nabble.com> <19827720.post@talk.nabble.com> <19828568.post@talk.nabble.com> Message-ID: <19829936.post@talk.nabble.com> beautiful, it works now. Thank you Edwin. so when I want to use spawn_link() with a named function that function has to be exported? same stands for regular spawn()? just a side question: once a certain "receive" configuration is set for a process it can never be changed to another "receive" configuration? it just popped in my head here when you said that i can inline the error "receive". thanks for your time Edwin Fine wrote: > > Well, there are a couple of problems, but the reason why you get that > warning is that you have to export a function that you spawn_link to using > Module/Func/Args syntax, otherwise you would have to > > Handler_process = spawn_link(fun() -> data_process(Socket, []) end), > > The other problem is that your fun Listen_for_errors may as well be > inline, i.e. you could change this code: > > %----------------------------------------------- > Listen_for_errors = > fun() -> > io:format("listening started~n"), > receive > {'EXIT', Pid, Why} -> > io:format("~p exited because:~p", [Pid,Why]); > Other -> > io:format("Other:~p~n", [Other]) > end > end, > Listen_for_errors(), > %----------------------------------------------- > > Handler_process = spawn_link(?MODULE, data_process, [Socket, []]), > > To this: > > %----------------------------------------------- > io:format("listening started~n"), > receive > {'EXIT', Pid, Why} -> > io:format("~p exited because:~p", [Pid,Why]); > Other -> > io:format("Other:~p~n", [Other]) > end, > %----------------------------------------------- > > Handler_process = spawn_link(?MODULE, data_process, [Socket, []]), > > > -- View this message in context: http://www.nabble.com/wierd-%22function-not-used%22-problem---code-included-tp19826465p19829936.html Sent from the Erlang Questions mailing list archive at Nabble.com. From antoine.koener Mon Oct 6 01:12:31 2008 From: antoine.koener (Antoine Koener) Date: Mon, 6 Oct 2008 01:12:31 +0200 Subject: [erlang-questions] a little meta-programing help In-Reply-To: <8ca3fbe80810051515m6b983822re94985aa0b63248c@mail.gmail.com> References: <8ca3fbe80810051515m6b983822re94985aa0b63248c@mail.gmail.com> Message-ID: <1c89b3a10810051612r6e341282v54d0f94262072dbb@mail.gmail.com> On Mon, Oct 6, 2008 at 12:15 AM, anders conbere wrote: > Today I sat down to try to make working with mochiweb a little cleaner > for myself. I wanted a way to specify a list of mappings between url > patterns and methods to be called with the matched variables from > them. I quickly ran into issues with not being able to create patterns > dynamically, and then tried using funs to wrap that functionality but > pretty soon I was back at the same mess I started with. > I used the list_to_atom fun to build the module name. This is not recommended but it's still really useful: check out: http://easyerl.blogspot.com/2008/07/my-mochiweb-webservice.html -- http://easyerl.blogspot.com/ http://www.open-tools.org/ From aconbere Mon Oct 6 01:31:29 2008 From: aconbere (anders conbere) Date: Sun, 5 Oct 2008 16:31:29 -0700 Subject: [erlang-questions] a little meta-programing help In-Reply-To: <1c89b3a10810051612r6e341282v54d0f94262072dbb@mail.gmail.com> References: <8ca3fbe80810051515m6b983822re94985aa0b63248c@mail.gmail.com> <1c89b3a10810051612r6e341282v54d0f94262072dbb@mail.gmail.com> Message-ID: <8ca3fbe80810051631t2a1650f5x975f927c91e23415@mail.gmail.com> On Sun, Oct 5, 2008 at 4:12 PM, Antoine Koener wrote: > On Mon, Oct 6, 2008 at 12:15 AM, anders conbere wrote: >> Today I sat down to try to make working with mochiweb a little cleaner >> for myself. I wanted a way to specify a list of mappings between url >> patterns and methods to be called with the matched variables from >> them. I quickly ran into issues with not being able to create patterns >> dynamically, and then tried using funs to wrap that functionality but >> pretty soon I was back at the same mess I started with. >> > > I used the list_to_atom fun to build the module name. > This is not recommended but it's still really useful: > check out: http://easyerl.blogspot.com/2008/07/my-mochiweb-webservice.html Yeah, so I'm working more under the presumption that I can specify the route to the module for each mapped url pattern. I'm not supper interested in mapping urls to modules from the actual url text. Thanks, ~ Anders > > -- > > http://easyerl.blogspot.com/ > http://www.open-tools.org/ > From erlang-questions_efine Mon Oct 6 03:06:22 2008 From: erlang-questions_efine (Edwin Fine) Date: Sun, 5 Oct 2008 18:06:22 -0700 (PDT) Subject: [erlang-questions] wierd "function not used" problem - code included In-Reply-To: <19829936.post@talk.nabble.com> References: <19826465.post@talk.nabble.com> <19827659.post@talk.nabble.com> <19827696.post@talk.nabble.com> <19827720.post@talk.nabble.com> <19828568.post@talk.nabble.com> <19829936.post@talk.nabble.com> Message-ID: <19830744.post@talk.nabble.com> deepblue_other wrote: > > so when I want to use spawn_link() with a named function that function has > to be exported? > same stands for regular spawn()? > Yes, if you use a spawn that takes Module, Function, Args, like spawn/3, spawn/4, spawn_link/3, spawn_link/4,.... Or apply/3. And so on. In general if you provide a so-called "MFA" (Module, Func, Args) to a function, the Func has to be exported from Module, even if the Func is only for internal use within Module. It's important to know that the shell is your friend. It's critical to try out little pieces of code in the shell to see if they work the way you expect. For example, if you wanted to see if spawn could see your data_process function, you could have tried it in the shell (I'm passing the atom 'junk' instead of a real socket because I know the call will fail because it's not exported, so the socket is not needed): 1> c(tcp_manager). ./tcp_manager.erl:33: Warning: function data_process/2 is unused {ok,tcp_manager} 2> spawn(tcp_manager, data_process, [junk, []]). <0.40.0> 3> =ERROR REPORT==== 5-Oct-2008::20:49:23 === Error in process <0.40.0> with exit value: {undef,[{tcp_manager,data_process,[junk,[]]}]} deepblue_other wrote: > > just a side question: > once a certain "receive" configuration is set for a process it can never > be changed to another "receive" configuration? it just popped in my head > here when you said that i can inline the error "receive". > I perhaps did not make myself clear. What I meant by saying you could inline it is that I didn't see the value of writing Fun = fun() -> do_something(), do_something_else() end, Fun(). That's the same as writing do_something(), do_something_else() It is better in this case to put the code into a separate function. Better, because you can hot-swap the code and change that function. There's an excellent article about hot code swapping http://http://spawnlink.com/articles/rules-of-hot-code-swapping/ here . > %----------------------------------------------- > Listen_for_errors = > fun() -> > io:format("listening started~n"), > receive > {'EXIT', Pid, Why} -> > io:format("~p exited because:~p", [Pid,Why]); > Other -> > io:format("Other:~p~n", [Other]) > end > end, > Listen_for_errors(), > %----------------------------------------------- > Finally, I'm not sure what Listen_for_errors() is supposed to do. It's just going to sit there forever in the receive, waiting for the first message that is sent (or en exit signal), and print it out (thus throwing it away), and return. What did you want it to do? -- View this message in context: http://www.nabble.com/wierd-%22function-not-used%22-problem---code-included-tp19826465p19830744.html Sent from the Erlang Questions mailing list archive at Nabble.com. From cktgatb Mon Oct 6 03:13:59 2008 From: cktgatb (deepblue_other) Date: Sun, 5 Oct 2008 18:13:59 -0700 (PDT) Subject: [erlang-questions] Erlang external binary term format Message-ID: <19830781.post@talk.nabble.com> term_to_binary() outputs a binary. what is the format of that binary? I would like to create a "unpacker/packer" for that format in ActionScript3, and avoid the use of XML (which Im using now for Flash-to-Erlang) communication altogether. it would be faster, less code, and much more efficient from the bandwidth point of view. is there a document someplace that gives the byte layout maybe? thank you -- View this message in context: http://www.nabble.com/Erlang-external-binary-term-format-tp19830781p19830781.html Sent from the Erlang Questions mailing list archive at Nabble.com. From cktgatb Mon Oct 6 03:29:57 2008 From: cktgatb (deepblue_other) Date: Sun, 5 Oct 2008 18:29:57 -0700 (PDT) Subject: [erlang-questions] Erlang external binary term format In-Reply-To: <19830781.post@talk.nabble.com> References: <19830781.post@talk.nabble.com> Message-ID: <19830881.post@talk.nabble.com> for example one day I was looking at the term_to_binary() output of {binaries,"are",useful} and it was: 131,104,3,100,0,8,98,105,110,97,114,105,101,115,107,0,3,97,114,101,100,0,6,117,115,101,102,117,108 so with a little experimentation with other tuples I got these rules so far: 131,104 - this means that its a tuple 3 - this means that it has 3 terms 100 and 107 - type code - in this case 100 stands for atoms, and 107 stands for strings 0 - is the separator between the "type code"(name I gave it just now ;) ) and the actual ASCII sequence 8 and 3(again) and 6 - these indicate the length of the binary sequence (number of ASCII characters in this case so: binaries - 100(type code),0,8(byte length),98,105,110,97,114,105,101,115 "are" - 107(type code),0,3(byte length),97,114,101 useful - 100(type code),0,6(byte length),117,115,101,102,117,108 this just explains a limited set, doesnt go into lists... I could be wrong, but the rules seem to match up other examples as well thanks deepblue_other wrote: > > term_to_binary() outputs a binary. > what is the format of that binary? I would like to create a > "unpacker/packer" for that format in ActionScript3, and avoid the use of > XML (which Im using now for Flash-to-Erlang) communication altogether. it > would be faster, less code, and much more efficient from the bandwidth > point of view. > > is there a document someplace that gives the byte layout maybe? > thank you > -- View this message in context: http://www.nabble.com/Erlang-external-binary-term-format-tp19830781p19830881.html Sent from the Erlang Questions mailing list archive at Nabble.com. From ok Mon Oct 6 04:49:11 2008 From: ok (Richard O'Keefe) Date: Mon, 6 Oct 2008 15:49:11 +1300 Subject: [erlang-questions] [Haskell-cafe] Haskell-cafe-cafe? Was: Re: Health effects In-Reply-To: <22281_1219415383_m7MERn3A020400_24d4f39c0808220634l49188cdet690a703606a4861e@mail.gmail.com> References: <22281_1219415383_m7MERn3A020400_24d4f39c0808220634l49188cdet690a703606a4861e@mail.gmail.com> Message-ID: <9F06040A-24F4-4E55-8D5E-C8678CE36653@cs.otago.ac.nz> On 6 Oct 2008, at 1:54 am, Andrew Coppin wrote: > Hi, > > If I have a list of a fixed size (say 10,000 elements). What is the > most efficient way to add a new item to the list and force out the old > first element. It depends on where you want to add the new item. If you want it at the front, just New_List = [New_Item | tail(Old_List)] is pretty hard to improve on. If you want to add the new item anywhere else, you will have to copy. > I'm currently doing a double reverse trick, e.g. : > > Eshell V5.6.3 (abort with ^G) > 1> L1 = ["A", "B", "C", "D", "E"]. > ["A","B","C","D","E"] > 2> [_ | L2] = L1. > ["A","B","C","D","E"] > 3> lists:reverse(["F" | lists:reverse(L2)]). > ["B","C","D","E","F"] It appears that you are putting the new item at the end, which is the costliest possible place to put it. You are also doing it in two passes, when it can be done in one. snoc(X, [Y|Ys]) -> [Y|snoc(X, Ys)]; snoc(X, []) -> [X]. New_List = snoc(New_Item, tail(Old_List)) The first question you have to ask yourself is "why do I *care* where the new item goes?" The second question you have to ask is "given that I need a *sequence* where the order has to be thus-and-such for such-and-such reasons, is a list the right data structure to represent this sequence?" It may well be that a list is the wrong data structure. Perhaps you need a queue (and it just so happens that there is a 'queue' module in Erlang's stdlib). Perhaps you need some more general sequence type, in which case several of Chris Okasaki's functional data structures have been converted to Erlang and are available. From ok Mon Oct 6 04:30:06 2008 From: ok (Richard O'Keefe) Date: Mon, 6 Oct 2008 15:30:06 +1300 Subject: [erlang-questions] re cursive fun() In-Reply-To: <19820386.post@talk.nabble.com> References: <19820386.post@talk.nabble.com> Message-ID: On 5 Oct 2008, at 4:19 pm, deepblue_other wrote: > I have this going on > > FunVar = > fun() -> > ... > FunVar() > end. > Shouldn't this go in a FAQ somewhere? Maybe it belongs in the reference manual. The quick answer is that if you need a recursive function, why not write a recursive function in the usual way? There's something particularly nasty about this example. One normally proves (or at any rate argues with vigourously waving hands for) the termination of a recursive function by showing that some non-negative measure of its arguments strictly decreases on each recursive call, but this function has no arguments. I think we need to see more of it. The long answer is that you can always do Rec = fun (Self, Args) -> .... Self(Self, Args') end, Foo = fun (Args) -> Rec(Rec, Args) end, It's possible, but you are working against the grain of the language, and there is most likely a better way to achieve your goals. From lloy0076 Mon Oct 6 07:31:23 2008 From: lloy0076 (David Lloyd) Date: Mon, 06 Oct 2008 16:01:23 +1030 Subject: [erlang-questions] Erlang Course on Web-Site (IP Rights) Message-ID: <48E9A2AB.5090907@adam.com.au> Hi There, The Erlang Course: * http://www.erlang.org/course/course.html ...doesn't have any obvious attribution as to who or what legal entity owns the copyright and other rights to it. Does anyone know who the IP owner actually is and if there are any specific restrictions on its use (eg. not in a commercial setting)? DSL From chsu79 Mon Oct 6 08:12:01 2008 From: chsu79 (Christian) Date: Mon, 6 Oct 2008 08:12:01 +0200 Subject: [erlang-questions] Erlang external binary term format In-Reply-To: <19830881.post@talk.nabble.com> References: <19830781.post@talk.nabble.com> <19830881.post@talk.nabble.com> Message-ID: You might want to look at ./erts/emulator/internal_doc/erl_ext_dist.txt in the source tree. On Mon, Oct 6, 2008 at 3:29 AM, deepblue_other wrote: > > for example > one day I was looking at the term_to_binary() output of > {binaries,"are",useful} > and it was: > 131,104,3,100,0,8,98,105,110,97,114,105,101,115,107,0,3,97,114,101,100,0,6,117,115,101,102,117,108 From dgud Mon Oct 6 09:32:31 2008 From: dgud (Dan Gudmundsson) Date: Mon, 06 Oct 2008 09:32:31 +0200 Subject: [erlang-questions] Some mnesia oddity In-Reply-To: <269388e30810050420w38e3cc77h23dea901c39d6cc1@mail.gmail.com> References: <48B7DB67.7010608@erix.ericsson.se> <269388e30810050420w38e3cc77h23dea901c39d6cc1@mail.gmail.com> Message-ID: <48E9BF0F.7080303@erix.ericsson.se> You should be able to read the table in the same transaction, but there is a bug in mnesia handling the special atom '_'. delete_object is not match delete do you have records with '_' in them?? /Dan Ben Hood wrote: > Hi, > > I know this is an old thread but I was wondering where the behaviour I > am seeing is in any way related to passing in a pattern to > mnesia:delete_object/1. > > On Fri, Aug 29, 2008 at 12:20 PM, Dan Gudmundsson wrote: >>> We found a strange mnesia behavior here... >>> >>> Some mnesia:write operations after a mnesia:delete_object seem to >>> not have the expected result when executed in the same transaction. >>> >>> See attached example file: >>> 1 - We fill a test_table >>> 2 - In the same transaction, we read all records, delete them, and >>> write them back (do not ask why :)) >>> 3 - Surprise! Only a subset of them can be read afterwards >>> >>> Same result in R11 and R12. >>> >>> It works if the delete_object and write operations are in separate >>> transactions... But who knows what can happen between them... > > The code I am using (attached below) is similar to the above scenario. > > Basically what I want to know is if there is a way to delete records > from a table and then re-read the table in the same transaction, or > whether this must be in separate transactions. > > My use case is a densely populated table that I want to > > 1. Selectively delete some records for; > 2. Conditionally delete records from a different table if they no > longer have any references in the first table. > > So my approach could be characterized by a delete and sweep action. > > Of course I could implement this functionality manually by re-reading > the table and filtering out any results that I know will get deleted > when the transaction commits. But if I could get mnesia to do this, it > would be more elegant. > > Also, I could do this in two transactions and re-arrange the code so > to introduce something idempotent to get around the non-atomicity. > > But if this could be solved using mnesia, that would be cool :-) > > Thx, > > Ben > > ---snip--- > > -module(sync_test). > > -compile(export_all). > > -record(outer,{inner, const = const}). > -record(inner,{a,b,c}). > > init() -> > mnesia:start(), > mnesia:delete_table(outer), > {atomic,ok} = mnesia:create_table(outer, > [{type,ordered_set}, > {attributes, record_info(fields, outer)}]), > ok. > > insert() -> > Record = #outer{inner = #inner{a = 1, b = 2, c = now()}}, > mnesia:transaction(fun() -> mnesia:write(Record) end). > > one_tx() -> > Record = #outer{inner = #inner{a = 1, b = 2, c = '_'}}, > mnesia:sync_transaction( > fun() -> > mnesia:delete_object(Record), > io:format("~p~n",[mnesia:match_object(Record)]) > end). > > two_tx() -> > Record = #outer{inner = #inner{a = 1, b = 2, c = '_'}}, > mnesia:sync_transaction( > fun() -> > mnesia:delete_object(Record) > end), > mnesia:sync_transaction( > fun() -> > io:format("~p~n",[mnesia:match_object(Record)]) > end). > From joelr1 Mon Oct 6 09:53:52 2008 From: joelr1 (Joel Reymont) Date: Mon, 6 Oct 2008 08:53:52 +0100 Subject: [erlang-questions] Time to client > time to server?! Is my testing flawed? Please help me explain my results! Message-ID: Folks, I run Mac OSX 10.5.5 on a Mac Pro 2x2.8Ghz Xeon, 14Gb of memory. Erlang (BEAM) emulator version 5.6.3 [source] [64-bit] [smp:8] [async- threads:2] [kernel-poll:true] I found that when I run everything on a single VM and launch 500 games everything runs through just fine. I then distributed my OpenPoker test harness over 3 VMs: one hosts Mnesia tables and launches games, one runs games and launches bots, one runs the bots. The last two VMs are added as extra Mnesia nodes, i.e. have RAM copies of tables. Here's is when I started getting player timeouts. Each player (bot actually) is supposed to make a bet within 15 seconds but a lot of bots fail to do so in a distributed configuration. Unlike my previous testing, I now launch all games at the same time. There are about 5 players per game so 500 games would make about 2500 player bots and the same amount of open sockets. Dumping core upon a player timeout reveals that most of queue lengths are 0, a lot of queues have just 1 message in them and two queues have 2 messages. I decided to time packets and measure the time it takes for a packet to travel from the server to the client and from the client to the server. This is where I got results that I can't quite explain... The time a packet travels from a server to the client is consistently greater by a large margin!!! Would someone kindly offer an explanation? Rather than adding timestamps to each individual packet, I send a ping packet right after any packet the server sends out. I do this from my tcpsend macro, i.e. -define(tcpsend(Socket, Data), fun() -> XXX = pp:write(Data), case catch gen_tcp:send(Socket, XXX) of ok -> ok; ... end, YYY = pp:write(#ping{}), case catch gen_tcp:send(Socket, YYY) of ok -> ok; ... end end()). The ping packet looks like this: -record(ping, { send_time = now() }). Once a bot receives the ping packet, it sends a pong back: handle_ping(R, Bot) -> handle_cast(#pong{ orig_send_time = R#ping.send_time }, Bot), {noreply, Bot}. Here I copy the original send time into the pong packet and stamp it with send time on the bot side: -record(pong, { orig_send_time, send_time = now(), recv_time }). Once my server receives the pong packet, it plugs receive time in: process_pong(Client, _Socket, R) -> R1 = R#pong{ recv_time = now() }, gen_server:cast(Client#client.server, {'PONG', R1}), Client. I measure the time to client by subtracting original send time from the bot send time. The bots are dumb, they reply back as quickly as possible and don't contain any logic so there's should be very little overhead on the bot side. The time to server is the difference between time of receipt on the server side and the bot send time. handle_cast({'PONG', R = #pong{}}, Server) -> TC = timer:now_diff(R#pong.send_time, R#pong.orig_send_time), TS = timer:now_diff(R#pong.recv_time, R#pong.send_time), gen_server:cast(?STATS, {'AVG', time_to_client, TC}), gen_server:cast(?STATS, {'AVG', time_to_server, TS}), {noreply, Server}; I have a separate "statistics" server that keeps track of averages: handle_cast({'AVG', Id, New}, Data) -> Old = case gb_trees:lookup(Id, Data#stats.avg) of {value, Val} -> Val; none -> 0 end, Avg1 = gb_trees:enter(Id, (Old + New) / 2, Data#stats.avg), {noreply, Data#stats{ avg = Avg1 }}; When dumping stats, I divide averages by 1000 to get time in milliseconds. So far so good? Here are the results from testing on a single VM. Note that at some point the time to server starts to exceed the time to client. Timings from testing on a cluster of 3 VMs follow at the bottom. --- single VM --- gateway:start('1', 4000, 500000) Waiting for game servers... Starting a port server on 4000... Simulating gameplay with 500 games... 50 games started, 262 players 100 games started, 504 players 150 games started, 743 players 200 games started, 1019 players 250 games started, 1288 players 300 games started, 1529 players 350 games started, 1766 players 400 games started, 2057 players 450 games started, 2304 players 500 games started, 2562 players dmb: 500 games launching simultaneously dmb: waiting for games to end... =INFO REPORT==== 6-Oct-2008::08:14:55 === module: stats elapsed: 5.000022 time_to_client: 0.3116982504004592 time_to_server: 0.26828120427789537 bytes: 110919 packets: 6202 {bytes,per_sec}: 22183 {packets,per_sec}: 1240 =INFO REPORT==== 6-Oct-2008::08:15:00 === module: stats elapsed: 4.999943 time_to_client: 0.335493890834141 time_to_server: 0.2682274480913192 bytes: 35447 packets: 1984 {bytes,per_sec}: 7089 {packets,per_sec}: 396 =INFO REPORT==== 6-Oct-2008::08:15:10 === module: stats elapsed: 4.999295 time_to_client: 0.8764044453192754 time_to_server: 0.5871947161189068 bytes: 600493 packets: 25147 {bytes,per_sec}: 120115 {packets,per_sec}: 5030 =INFO REPORT==== 6-Oct-2008::08:15:15 === module: stats elapsed: 5.000729 time_to_client: 0.416 time_to_server: 198.9885 bytes: 25 packets: 1 {bytes,per_sec}: 4 {packets,per_sec}: 0 =INFO REPORT==== 6-Oct-2008::08:15:25 === module: stats elapsed: 5.131727 time_to_client: 4.039440742060922 time_to_server: 44.38444315504353 bytes: 49034 packets: 1979 {bytes,per_sec}: 9555 {packets,per_sec}: 385 =INFO REPORT==== 6-Oct-2008::08:15:30 === module: stats elapsed: 4.994361 time_to_client: 5.236234569474154 time_to_server: 15.505128105674318 bytes: 8907 packets: 358 {bytes,per_sec}: 1783 {packets,per_sec}: 71 50 games finished =INFO REPORT==== 6-Oct-2008::08:15:35 === module: stats elapsed: 4.923643 time_to_client: 7.458330178363772 time_to_server: 49.56836180504743 bytes: 14380 packets: 581 {bytes,per_sec}: 2920 {packets,per_sec}: 118 100 games finished 150 games finished =INFO REPORT==== 6-Oct-2008::08:15:40 === module: stats elapsed: 5.014354 time_to_client: 10.303327121777983 time_to_server: 64.27703119134696 bytes: 23849 packets: 960 {bytes,per_sec}: 4756 {packets,per_sec}: 191 200 games finished 250 games finished 300 games finished =INFO REPORT==== 6-Oct-2008::08:15:45 === module: stats elapsed: 4.973468 time_to_client: 13.492860654918857 time_to_server: 106.97844814674687 bytes: 28758 packets: 1162 {bytes,per_sec}: 5782 {packets,per_sec}: 233 350 games finished 400 games finished 450 games finished =INFO REPORT==== 6-Oct-2008::08:15:50 === module: stats elapsed: 4.965927 time_to_client: 20.687073726427755 time_to_server: 46.96422948544525 bytes: 76007 packets: 3071 {bytes,per_sec}: 15305 {packets,per_sec}: 618 500 games finished dmb: exited successfully, 58.529502 seconds elapsed ok (1)5> =INFO REPORT==== 6-Oct-2008::08:15:55 === module: stats elapsed: 4.996499 time_to_client: 1.8395921187621034 time_to_server: 3.3051747276788346 bytes: 3845004 packets: 161772 {bytes,per_sec}: 769539 {packets,per_sec}: 32377 Here are the baffling results from testing on a cluster of 3 separate VMs. Note that the time to client is consistently higher and reaches 3.5 seconds at the end, when the game VM is forced to crash upon a player timeout. --- Distributed --- (1)2> dmb:test(500) gateway:start('1', 4000, 500000) Waiting for game servers... Starting a port server on 4000... Simulating gameplay with 500 games... 50 games started, 262 players 100 games started, 504 players 150 games started, 743 players 200 games started, 1019 players 250 games started, 1288 players 300 games started, 1529 players 350 games started, 1766 players 400 games started, 2057 players 450 games started, 2304 players 500 games started, 2562 players dmb: 500 games launching simultaneously dmb: waiting for games to end... =INFO REPORT==== 6-Oct-2008::08:17:12 === module: stats elapsed: 5.000164 time_to_client: 0.7472338659989799 time_to_server: 0.2868026026862225 bytes: 97276 packets: 5438 {bytes,per_sec}: 19454 {packets,per_sec}: 1087 =INFO REPORT==== 6-Oct-2008::08:17:17 === module: stats elapsed: 4.999986 time_to_client: 0.9655462464556185 time_to_server: 0.30163815339577854 bytes: 49090 packets: 2748 {bytes,per_sec}: 9818 {packets,per_sec}: 549 =INFO REPORT==== 6-Oct-2008::08:17:22 === module: stats elapsed: 4.999992 =INFO REPORT==== 6-Oct-2008::08:17:27 === module: stats elapsed: 5.000022 time_to_client: 903.3217931168908 time_to_server: 8.179055363354317 bytes: 346499 packets: 14736 {bytes,per_sec}: 69299 {packets,per_sec}: 2947 =INFO REPORT==== 6-Oct-2008::08:17:32 === module: stats elapsed: 4.999981 time_to_client: 301.7944063249315 time_to_server: 0.13660450764194335 bytes: 254019 packets: 10412 {bytes,per_sec}: 50803 {packets,per_sec}: 2082 =INFO REPORT==== 6-Oct-2008::08:17:37 === module: stats elapsed: 5.000355 time_to_client: 185.66359294523173 time_to_server: 2.651532941434563 bytes: 63537 packets: 2565 {bytes,per_sec}: 12706 {packets,per_sec}: 512 =INFO REPORT==== 6-Oct-2008::08:17:42 === module: stats elapsed: 4.999885 time_to_client: 1501.014993336486 time_to_server: 35.811546393119464 bytes: 405683 packets: 16375 {bytes,per_sec}: 81138 {packets,per_sec}: 3275 vvvvv the game serving VM crash dumps here, as requested ** exception error: no case clause matching noconnection in function dmb:wait_for_games/1 (1)3> =INFO REPORT==== 6-Oct-2008::08:17:47 === module: stats elapsed: 4.999809 time_to_client: 3496.1493304273376 time_to_server: 0.09871293629933679 bytes: 286105 packets: 11573 {bytes,per_sec}: 57223 {packets,per_sec}: 2314 -- wagerlabs.com From joelr1 Mon Oct 6 09:53:52 2008 From: joelr1 (Joel Reymont) Date: Mon, 6 Oct 2008 08:53:52 +0100 Subject: [erlang-questions] Time to client > time to server?! Is my testing flawed? Please help me explain my results! Message-ID: Folks, I run Mac OSX 10.5.5 on a Mac Pro 2x2.8Ghz Xeon, 14Gb of memory. Erlang (BEAM) emulator version 5.6.3 [source] [64-bit] [smp:8] [async- threads:2] [kernel-poll:true] I found that when I run everything on a single VM and launch 500 games everything runs through just fine. I then distributed my OpenPoker test harness over 3 VMs: one hosts Mnesia tables and launches games, one runs games and launches bots, one runs the bots. The last two VMs are added as extra Mnesia nodes, i.e. have RAM copies of tables. Here's is when I started getting player timeouts. Each player (bot actually) is supposed to make a bet within 15 seconds but a lot of bots fail to do so in a distributed configuration. Unlike my previous testing, I now launch all games at the same time. There are about 5 players per game so 500 games would make about 2500 player bots and the same amount of open sockets. Dumping core upon a player timeout reveals that most of queue lengths are 0, a lot of queues have just 1 message in them and two queues have 2 messages. I decided to time packets and measure the time it takes for a packet to travel from the server to the client and from the client to the server. This is where I got results that I can't quite explain... The time a packet travels from a server to the client is consistently greater by a large margin!!! Would someone kindly offer an explanation? Rather than adding timestamps to each individual packet, I send a ping packet right after any packet the server sends out. I do this from my tcpsend macro, i.e. -define(tcpsend(Socket, Data), fun() -> XXX = pp:write(Data), case catch gen_tcp:send(Socket, XXX) of ok -> ok; ... end, YYY = pp:write(#ping{}), case catch gen_tcp:send(Socket, YYY) of ok -> ok; ... end end()). The ping packet looks like this: -record(ping, { send_time = now() }). Once a bot receives the ping packet, it sends a pong back: handle_ping(R, Bot) -> handle_cast(#pong{ orig_send_time = R#ping.send_time }, Bot), {noreply, Bot}. Here I copy the original send time into the pong packet and stamp it with send time on the bot side: -record(pong, { orig_send_time, send_time = now(), recv_time }). Once my server receives the pong packet, it plugs receive time in: process_pong(Client, _Socket, R) -> R1 = R#pong{ recv_time = now() }, gen_server:cast(Client#client.server, {'PONG', R1}), Client. I measure the time to client by subtracting original send time from the bot send time. The bots are dumb, they reply back as quickly as possible and don't contain any logic so there's should be very little overhead on the bot side. The time to server is the difference between time of receipt on the server side and the bot send time. handle_cast({'PONG', R = #pong{}}, Server) -> TC = timer:now_diff(R#pong.send_time, R#pong.orig_send_time), TS = timer:now_diff(R#pong.recv_time, R#pong.send_time), gen_server:cast(?STATS, {'AVG', time_to_client, TC}), gen_server:cast(?STATS, {'AVG', time_to_server, TS}), {noreply, Server}; I have a separate "statistics" server that keeps track of averages: handle_cast({'AVG', Id, New}, Data) -> Old = case gb_trees:lookup(Id, Data#stats.avg) of {value, Val} -> Val; none -> 0 end, Avg1 = gb_trees:enter(Id, (Old + New) / 2, Data#stats.avg), {noreply, Data#stats{ avg = Avg1 }}; When dumping stats, I divide averages by 1000 to get time in milliseconds. So far so good? Here are the results from testing on a single VM. Note that at some point the time to server starts to exceed the time to client. Timings from testing on a cluster of 3 VMs follow at the bottom. --- single VM --- gateway:start('1', 4000, 500000) Waiting for game servers... Starting a port server on 4000... Simulating gameplay with 500 games... 50 games started, 262 players 100 games started, 504 players 150 games started, 743 players 200 games started, 1019 players 250 games started, 1288 players 300 games started, 1529 players 350 games started, 1766 players 400 games started, 2057 players 450 games started, 2304 players 500 games started, 2562 players dmb: 500 games launching simultaneously dmb: waiting for games to end... =INFO REPORT==== 6-Oct-2008::08:14:55 === module: stats elapsed: 5.000022 time_to_client: 0.3116982504004592 time_to_server: 0.26828120427789537 bytes: 110919 packets: 6202 {bytes,per_sec}: 22183 {packets,per_sec}: 1240 =INFO REPORT==== 6-Oct-2008::08:15:00 === module: stats elapsed: 4.999943 time_to_client: 0.335493890834141 time_to_server: 0.2682274480913192 bytes: 35447 packets: 1984 {bytes,per_sec}: 7089 {packets,per_sec}: 396 =INFO REPORT==== 6-Oct-2008::08:15:10 === module: stats elapsed: 4.999295 time_to_client: 0.8764044453192754 time_to_server: 0.5871947161189068 bytes: 600493 packets: 25147 {bytes,per_sec}: 120115 {packets,per_sec}: 5030 =INFO REPORT==== 6-Oct-2008::08:15:15 === module: stats elapsed: 5.000729 time_to_client: 0.416 time_to_server: 198.9885 bytes: 25 packets: 1 {bytes,per_sec}: 4 {packets,per_sec}: 0 =INFO REPORT==== 6-Oct-2008::08:15:25 === module: stats elapsed: 5.131727 time_to_client: 4.039440742060922 time_to_server: 44.38444315504353 bytes: 49034 packets: 1979 {bytes,per_sec}: 9555 {packets,per_sec}: 385 =INFO REPORT==== 6-Oct-2008::08:15:30 === module: stats elapsed: 4.994361 time_to_client: 5.236234569474154 time_to_server: 15.505128105674318 bytes: 8907 packets: 358 {bytes,per_sec}: 1783 {packets,per_sec}: 71 50 games finished =INFO REPORT==== 6-Oct-2008::08:15:35 === module: stats elapsed: 4.923643 time_to_client: 7.458330178363772 time_to_server: 49.56836180504743 bytes: 14380 packets: 581 {bytes,per_sec}: 2920 {packets,per_sec}: 118 100 games finished 150 games finished =INFO REPORT==== 6-Oct-2008::08:15:40 === module: stats elapsed: 5.014354 time_to_client: 10.303327121777983 time_to_server: 64.27703119134696 bytes: 23849 packets: 960 {bytes,per_sec}: 4756 {packets,per_sec}: 191 200 games finished 250 games finished 300 games finished =INFO REPORT==== 6-Oct-2008::08:15:45 === module: stats elapsed: 4.973468 time_to_client: 13.492860654918857 time_to_server: 106.97844814674687 bytes: 28758 packets: 1162 {bytes,per_sec}: 5782 {packets,per_sec}: 233 350 games finished 400 games finished 450 games finished =INFO REPORT==== 6-Oct-2008::08:15:50 === module: stats elapsed: 4.965927 time_to_client: 20.687073726427755 time_to_server: 46.96422948544525 bytes: 76007 packets: 3071 {bytes,per_sec}: 15305 {packets,per_sec}: 618 500 games finished dmb: exited successfully, 58.529502 seconds elapsed ok (1)5> =INFO REPORT==== 6-Oct-2008::08:15:55 === module: stats elapsed: 4.996499 time_to_client: 1.8395921187621034 time_to_server: 3.3051747276788346 bytes: 3845004 packets: 161772 {bytes,per_sec}: 769539 {packets,per_sec}: 32377 Here are the baffling results from testing on a cluster of 3 separate VMs. Note that the time to client is consistently higher and reaches 3.5 seconds at the end, when the game VM is forced to crash upon a player timeout. --- Distributed --- (1)2> dmb:test(500) gateway:start('1', 4000, 500000) Waiting for game servers... Starting a port server on 4000... Simulating gameplay with 500 games... 50 games started, 262 players 100 games started, 504 players 150 games started, 743 players 200 games started, 1019 players 250 games started, 1288 players 300 games started, 1529 players 350 games started, 1766 players 400 games started, 2057 players 450 games started, 2304 players 500 games started, 2562 players dmb: 500 games launching simultaneously dmb: waiting for games to end... =INFO REPORT==== 6-Oct-2008::08:17:12 === module: stats elapsed: 5.000164 time_to_client: 0.7472338659989799 time_to_server: 0.2868026026862225 bytes: 97276 packets: 5438 {bytes,per_sec}: 19454 {packets,per_sec}: 1087 =INFO REPORT==== 6-Oct-2008::08:17:17 === module: stats elapsed: 4.999986 time_to_client: 0.9655462464556185 time_to_server: 0.30163815339577854 bytes: 49090 packets: 2748 {bytes,per_sec}: 9818 {packets,per_sec}: 549 =INFO REPORT==== 6-Oct-2008::08:17:22 === module: stats elapsed: 4.999992 =INFO REPORT==== 6-Oct-2008::08:17:27 === module: stats elapsed: 5.000022 time_to_client: 903.3217931168908 time_to_server: 8.179055363354317 bytes: 346499 packets: 14736 {bytes,per_sec}: 69299 {packets,per_sec}: 2947 =INFO REPORT==== 6-Oct-2008::08:17:32 === module: stats elapsed: 4.999981 time_to_client: 301.7944063249315 time_to_server: 0.13660450764194335 bytes: 254019 packets: 10412 {bytes,per_sec}: 50803 {packets,per_sec}: 2082 =INFO REPORT==== 6-Oct-2008::08:17:37 === module: stats elapsed: 5.000355 time_to_client: 185.66359294523173 time_to_server: 2.651532941434563 bytes: 63537 packets: 2565 {bytes,per_sec}: 12706 {packets,per_sec}: 512 =INFO REPORT==== 6-Oct-2008::08:17:42 === module: stats elapsed: 4.999885 time_to_client: 1501.014993336486 time_to_server: 35.811546393119464 bytes: 405683 packets: 16375 {bytes,per_sec}: 81138 {packets,per_sec}: 3275 vvvvv the game serving VM crash dumps here, as requested ** exception error: no case clause matching noconnection in function dmb:wait_for_games/1 (1)3> =INFO REPORT==== 6-Oct-2008::08:17:47 === module: stats elapsed: 4.999809 time_to_client: 3496.1493304273376 time_to_server: 0.09871293629933679 bytes: 286105 packets: 11573 {bytes,per_sec}: 57223 {packets,per_sec}: 2314 -- wagerlabs.com From joelr1 Mon Oct 6 09:53:52 2008 From: joelr1 (Joel Reymont) Date: Mon, 6 Oct 2008 08:53:52 +0100 Subject: [erlang-questions] Time to client > time to server?! Is my testing flawed? Please help me explain my results! Message-ID: Folks, I run Mac OSX 10.5.5 on a Mac Pro 2x2.8Ghz Xeon, 14Gb of memory. Erlang (BEAM) emulator version 5.6.3 [source] [64-bit] [smp:8] [async- threads:2] [kernel-poll:true] I found that when I run everything on a single VM and launch 500 games everything runs through just fine. I then distributed my OpenPoker test harness over 3 VMs: one hosts Mnesia tables and launches games, one runs games and launches bots, one runs the bots. The last two VMs are added as extra Mnesia nodes, i.e. have RAM copies of tables. Here's is when I started getting player timeouts. Each player (bot actually) is supposed to make a bet within 15 seconds but a lot of bots fail to do so in a distributed configuration. Unlike my previous testing, I now launch all games at the same time. There are about 5 players per game so 500 games would make about 2500 player bots and the same amount of open sockets. Dumping core upon a player timeout reveals that most of queue lengths are 0, a lot of queues have just 1 message in them and two queues have 2 messages. I decided to time packets and measure the time it takes for a packet to travel from the server to the client and from the client to the server. This is where I got results that I can't quite explain... The time a packet travels from a server to the client is consistently greater by a large margin!!! Would someone kindly offer an explanation? Rather than adding timestamps to each individual packet, I send a ping packet right after any packet the server sends out. I do this from my tcpsend macro, i.e. -define(tcpsend(Socket, Data), fun() -> XXX = pp:write(Data), case catch gen_tcp:send(Socket, XXX) of ok -> ok; ... end, YYY = pp:write(#ping{}), case catch gen_tcp:send(Socket, YYY) of ok -> ok; ... end end()). The ping packet looks like this: -record(ping, { send_time = now() }). Once a bot receives the ping packet, it sends a pong back: handle_ping(R, Bot) -> handle_cast(#pong{ orig_send_time = R#ping.send_time }, Bot), {noreply, Bot}. Here I copy the original send time into the pong packet and stamp it with send time on the bot side: -record(pong, { orig_send_time, send_time = now(), recv_time }). Once my server receives the pong packet, it plugs receive time in: process_pong(Client, _Socket, R) -> R1 = R#pong{ recv_time = now() }, gen_server:cast(Client#client.server, {'PONG', R1}), Client. I measure the time to client by subtracting original send time from the bot send time. The bots are dumb, they reply back as quickly as possible and don't contain any logic so there's should be very little overhead on the bot side. The time to server is the difference between time of receipt on the server side and the bot send time. handle_cast({'PONG', R = #pong{}}, Server) -> TC = timer:now_diff(R#pong.send_time, R#pong.orig_send_time), TS = timer:now_diff(R#pong.recv_time, R#pong.send_time), gen_server:cast(?STATS, {'AVG', time_to_client, TC}), gen_server:cast(?STATS, {'AVG', time_to_server, TS}), {noreply, Server}; I have a separate "statistics" server that keeps track of averages: handle_cast({'AVG', Id, New}, Data) -> Old = case gb_trees:lookup(Id, Data#stats.avg) of {value, Val} -> Val; none -> 0 end, Avg1 = gb_trees:enter(Id, (Old + New) / 2, Data#stats.avg), {noreply, Data#stats{ avg = Avg1 }}; When dumping stats, I divide averages by 1000 to get time in milliseconds. So far so good? Here are the results from testing on a single VM. Note that at some point the time to server starts to exceed the time to client. Timings from testing on a cluster of 3 VMs follow at the bottom. --- single VM --- gateway:start('1', 4000, 500000) Waiting for game servers... Starting a port server on 4000... Simulating gameplay with 500 games... 50 games started, 262 players 100 games started, 504 players 150 games started, 743 players 200 games started, 1019 players 250 games started, 1288 players 300 games started, 1529 players 350 games started, 1766 players 400 games started, 2057 players 450 games started, 2304 players 500 games started, 2562 players dmb: 500 games launching simultaneously dmb: waiting for games to end... =INFO REPORT==== 6-Oct-2008::08:14:55 === module: stats elapsed: 5.000022 time_to_client: 0.3116982504004592 time_to_server: 0.26828120427789537 bytes: 110919 packets: 6202 {bytes,per_sec}: 22183 {packets,per_sec}: 1240 =INFO REPORT==== 6-Oct-2008::08:15:00 === module: stats elapsed: 4.999943 time_to_client: 0.335493890834141 time_to_server: 0.2682274480913192 bytes: 35447 packets: 1984 {bytes,per_sec}: 7089 {packets,per_sec}: 396 =INFO REPORT==== 6-Oct-2008::08:15:10 === module: stats elapsed: 4.999295 time_to_client: 0.8764044453192754 time_to_server: 0.5871947161189068 bytes: 600493 packets: 25147 {bytes,per_sec}: 120115 {packets,per_sec}: 5030 =INFO REPORT==== 6-Oct-2008::08:15:15 === module: stats elapsed: 5.000729 time_to_client: 0.416 time_to_server: 198.9885 bytes: 25 packets: 1 {bytes,per_sec}: 4 {packets,per_sec}: 0 =INFO REPORT==== 6-Oct-2008::08:15:25 === module: stats elapsed: 5.131727 time_to_client: 4.039440742060922 time_to_server: 44.38444315504353 bytes: 49034 packets: 1979 {bytes,per_sec}: 9555 {packets,per_sec}: 385 =INFO REPORT==== 6-Oct-2008::08:15:30 === module: stats elapsed: 4.994361 time_to_client: 5.236234569474154 time_to_server: 15.505128105674318 bytes: 8907 packets: 358 {bytes,per_sec}: 1783 {packets,per_sec}: 71 50 games finished =INFO REPORT==== 6-Oct-2008::08:15:35 === module: stats elapsed: 4.923643 time_to_client: 7.458330178363772 time_to_server: 49.56836180504743 bytes: 14380 packets: 581 {bytes,per_sec}: 2920 {packets,per_sec}: 118 100 games finished 150 games finished =INFO REPORT==== 6-Oct-2008::08:15:40 === module: stats elapsed: 5.014354 time_to_client: 10.303327121777983 time_to_server: 64.27703119134696 bytes: 23849 packets: 960 {bytes,per_sec}: 4756 {packets,per_sec}: 191 200 games finished 250 games finished 300 games finished =INFO REPORT==== 6-Oct-2008::08:15:45 === module: stats elapsed: 4.973468 time_to_client: 13.492860654918857 time_to_server: 106.97844814674687 bytes: 28758 packets: 1162 {bytes,per_sec}: 5782 {packets,per_sec}: 233 350 games finished 400 games finished 450 games finished =INFO REPORT==== 6-Oct-2008::08:15:50 === module: stats elapsed: 4.965927 time_to_client: 20.687073726427755 time_to_server: 46.96422948544525 bytes: 76007 packets: 3071 {bytes,per_sec}: 15305 {packets,per_sec}: 618 500 games finished dmb: exited successfully, 58.529502 seconds elapsed ok (1)5> =INFO REPORT==== 6-Oct-2008::08:15:55 === module: stats elapsed: 4.996499 time_to_client: 1.8395921187621034 time_to_server: 3.3051747276788346 bytes: 3845004 packets: 161772 {bytes,per_sec}: 769539 {packets,per_sec}: 32377 Here are the baffling results from testing on a cluster of 3 separate VMs. Note that the time to client is consistently higher and reaches 3.5 seconds at the end, when the game VM is forced to crash upon a player timeout. --- Distributed --- (1)2> dmb:test(500) gateway:start('1', 4000, 500000) Waiting for game servers... Starting a port server on 4000... Simulating gameplay with 500 games... 50 games started, 262 players 100 games started, 504 players 150 games started, 743 players 200 games started, 1019 players 250 games started, 1288 players 300 games started, 1529 players 350 games started, 1766 players 400 games started, 2057 players 450 games started, 2304 players 500 games started, 2562 players dmb: 500 games launching simultaneously dmb: waiting for games to end... =INFO REPORT==== 6-Oct-2008::08:17:12 === module: stats elapsed: 5.000164 time_to_client: 0.7472338659989799 time_to_server: 0.2868026026862225 bytes: 97276 packets: 5438 {bytes,per_sec}: 19454 {packets,per_sec}: 1087 =INFO REPORT==== 6-Oct-2008::08:17:17 === module: stats elapsed: 4.999986 time_to_client: 0.9655462464556185 time_to_server: 0.30163815339577854 bytes: 49090 packets: 2748 {bytes,per_sec}: 9818 {packets,per_sec}: 549 =INFO REPORT==== 6-Oct-2008::08:17:22 === module: stats elapsed: 4.999992 =INFO REPORT==== 6-Oct-2008::08:17:27 === module: stats elapsed: 5.000022 time_to_client: 903.3217931168908 time_to_server: 8.179055363354317 bytes: 346499 packets: 14736 {bytes,per_sec}: 69299 {packets,per_sec}: 2947 =INFO REPORT==== 6-Oct-2008::08:17:32 === module: stats elapsed: 4.999981 time_to_client: 301.7944063249315 time_to_server: 0.13660450764194335 bytes: 254019 packets: 10412 {bytes,per_sec}: 50803 {packets,per_sec}: 2082 =INFO REPORT==== 6-Oct-2008::08:17:37 === module: stats elapsed: 5.000355 time_to_client: 185.66359294523173 time_to_server: 2.651532941434563 bytes: 63537 packets: 2565 {bytes,per_sec}: 12706 {packets,per_sec}: 512 =INFO REPORT==== 6-Oct-2008::08:17:42 === module: stats elapsed: 4.999885 time_to_client: 1501.014993336486 time_to_server: 35.811546393119464 bytes: 405683 packets: 16375 {bytes,per_sec}: 81138 {packets,per_sec}: 3275 vvvvv the game serving VM crash dumps here, as requested ** exception error: no case clause matching noconnection in function dmb:wait_for_games/1 (1)3> =INFO REPORT==== 6-Oct-2008::08:17:47 === module: stats elapsed: 4.999809 time_to_client: 3496.1493304273376 time_to_server: 0.09871293629933679 bytes: 286105 packets: 11573 {bytes,per_sec}: 57223 {packets,per_sec}: 2314 -- wagerlabs.com From erlang-questions_efine Mon Oct 6 12:20:53 2008 From: erlang-questions_efine (Edwin Fine) Date: Mon, 6 Oct 2008 03:20:53 -0700 (PDT) Subject: [erlang-questions] Erlang external binary term format In-Reply-To: <19830781.post@talk.nabble.com> References: <19830781.post@talk.nabble.com> Message-ID: <19835272.post@talk.nabble.com> deepblue_other wrote: > > term_to_binary() outputs a binary. > what is the format of that binary? > is there a document someplace that gives the byte layout maybe? > This is what you want: http://erlang.org/doc/apps/erts/erl_ext_dist.html Erlang external term format documentation You might want to search the Erlang mailing list before asking questions. A lot of your questions may be answered already. For example, a search using the words "external term format" found the answer to your question in seconds using http://www.erlang.org/faq.html Search the Erlang Mailing Lists -- View this message in context: http://www.nabble.com/Erlang-external-binary-term-format-tp19830781p19835272.html Sent from the Erlang Questions mailing list archive at Nabble.com. From thomas.arts Mon Oct 6 10:41:56 2008 From: thomas.arts (Thomas Arts) Date: Mon, 06 Oct 2008 10:41:56 +0200 Subject: [erlang-questions] QuickCheck @ Erlang User Conference Message-ID: <48E9CF54.8070300@ituniv.se> Quviq provides a QuickCheck course before this years Erlang User Conference. The course will take place in Stockholm, November 10-12, 2008. The course is ment for Erlang developers interested in test driven development. The course consists of two and a half days with a mixture of theory and practical sessions, and includes a one month QuickCheck licence, which can be used to gain further experience with our tool after the course is over. November, 10: 9:00 - 17:00 Properties and generators, Symbolic test cases, Positive and negative testing. November, 11: 9:00 - 17:00 Testing stateful systems, Protocol testing. November 13: 9:00 - 13:00 Minimizing counter-examples. You can get more information and register for the course by email to thomas.arts Registration is on a first come, first served basis and the number of seats is restricted to a maximum of 12. The price is 12 500 sek per participant. This price is excluding hotel costs. Participants are expected to book their hotel themselves. The course is given in collaboration with Sj?land&Thyselius. /Thomas From joelr1 Mon Oct 6 10:16:54 2008 From: joelr1 (Joel Reymont) Date: Mon, 6 Oct 2008 09:16:54 +0100 Subject: [erlang-questions] Time to client > time to server?! Is my testing flawed? Please help me explain my results! In-Reply-To: References: Message-ID: <0BD13575-3DF8-4AFC-BE33-D45B09D4D7A9@gmail.com> Here's a more revealing set of latency measurements. I'm now tracking the maximum time to client and time to server. Note the peak latency of over 8 seconds in a distributed scenario. --- Single VM --- (1)4> dmb:test(500). gateway:start('1', 4000, 500000) Waiting for game servers... Starting a port server on 4000... Simulating gameplay with 500 games... 50 games started, 262 players 100 games started, 504 players 150 games started, 743 players 200 games started, 1019 players 250 games started, 1288 players 300 games started, 1529 players 350 games started, 1766 players 400 games started, 2057 players 450 games started, 2304 players 500 games started, 2562 players dmb: 500 games launching simultaneously dmb: waiting for games to end... =INFO REPORT==== 6-Oct-2008::09:03:52 === module: stats elapsed: 10.000245 {time_to_client,max}: 4.32 {time_to_server,max}: 2.841 {time_to_client,avg}: 0.2320246180635134 {time_to_server,avg}: 0.22264713927830931 bytes: 146366 packets: 8186 {bytes,per_sec}: 14636 {packets,per_sec}: 818 =INFO REPORT==== 6-Oct-2008::09:04:02 === module: stats elapsed: 10.001825 {time_to_client,max}: 11.05 {time_to_server,max}: 411.33 {time_to_client,avg}: 1.5062184064818505 {time_to_server,avg}: 0.7171950578502572 bytes: 448415 packets: 18778 {bytes,per_sec}: 44833 {packets,per_sec}: 1877 =INFO REPORT==== 6-Oct-2008::09:04:12 === module: stats elapsed: 9.998174 {time_to_client,max}: 12.69 {time_to_server,max}: 418.076 {time_to_client,avg}: 0.4114940672586087 {time_to_server,avg}: 289.4916230003739 bytes: 152103 packets: 6370 {bytes,per_sec}: 15213 {packets,per_sec}: 637 =INFO REPORT==== 6-Oct-2008::09:04:22 === module: stats elapsed: 10.120701 {time_to_client,max}: 13.341 {time_to_server,max}: 49.669 {time_to_client,avg}: 5.355944891472721 {time_to_server,avg}: 5.743951365303288 bytes: 41369 packets: 1670 {bytes,per_sec}: 4087 {packets,per_sec}: 165 50 games finished 100 games finished 150 games finished =INFO REPORT==== 6-Oct-2008::09:04:32 === module: stats elapsed: 9.963557 {time_to_client,max}: 10.079 {time_to_server,max}: 83.54 {time_to_client,avg}: 7.568428330186793 {time_to_server,avg}: 47.86868493253832 bytes: 23612 packets: 951 {bytes,per_sec}: 2369 {packets,per_sec}: 95 200 games finished ... 450 games finished =INFO REPORT==== 6-Oct-2008::09:04:42 === module: stats elapsed: 9.924854 {time_to_client,max}: 25.995 {time_to_server,max}: 228.509 {time_to_client,avg}: 12.582011113358574 {time_to_server,avg}: 63.03305165784938 bytes: 56429 packets: 2277 {bytes,per_sec}: 5685 {packets,per_sec}: 229 500 games finished dmb: exited successfully, 58.173462 seconds elapsed ok (1)5> =INFO REPORT==== 6-Oct-2008::09:04:52 === module: stats elapsed: 9.990864 {time_to_client,max}: 242.641 {time_to_server,max}: 2591.385 {time_to_client,avg}: 1.396611881112888 {time_to_server,avg}: 4.433587847758173 bytes: 3924494 packets: 164982 {bytes,per_sec}: 392808 {packets,per_sec}: 16513 --- Distributed over 3 VMs --- (1)2> dmb:test(500). gateway:start('1', 4000, 500000) Waiting for game servers... Starting a port server on 4000... Simulating gameplay with 500 games... 50 games started, 262 players 100 games started, 504 players 150 games started, 743 players 200 games started, 1019 players 250 games started, 1288 players 300 games started, 1529 players 350 games started, 1766 players 400 games started, 2057 players 450 games started, 2304 players 500 games started, 2562 players dmb: 500 games launching simultaneously dmb: waiting for games to end... =INFO REPORT==== 6-Oct-2008::09:14:51 === module: stats elapsed: 10.000883 {time_to_client,max}: 6.587 {time_to_server,max}: 3.25 {time_to_client,avg}: 0.8858832584049455 {time_to_server,avg}: 0.3519747484853795 bytes: 146366 packets: 8186 {bytes,per_sec}: 14635 {packets,per_sec}: 818 =INFO REPORT==== 6-Oct-2008::09:15:01 === module: stats elapsed: 10.000688 {time_to_client,max}: 904.376 {time_to_server,max}: 180.778 {time_to_client,avg}: 392.1472970779772 {time_to_server,avg}: 11.501733445497706 bytes: 159498 packets: 6790 {bytes,per_sec}: 15948 {packets,per_sec}: 678 =INFO REPORT==== 6-Oct-2008::09:15:11 === module: stats elapsed: 9.998408 {time_to_client,max}: 2736.19 {time_to_server,max}: 453.471 {time_to_client,avg}: 287.5398604052754 {time_to_server,avg}: 0.3376213403517969 bytes: 441020 packets: 18358 {bytes,per_sec}: 44109 {packets,per_sec}: 1836 =INFO REPORT==== 6-Oct-2008::09:15:21 === module: stats elapsed: 10.000147 {time_to_client,max}: 7792.444 {time_to_server,max}: 748.145 {time_to_client,avg}: 6795.083519124172 {time_to_server,avg}: 1.8773269961041452 bytes: 696655 packets: 28135 {bytes,per_sec}: 69664 {packets,per_sec}: 2813 (1)3> =INFO REPORT==== 6-Oct-2008::09:15:31 === module: stats elapsed: 9.999866 {time_to_client,max}: 8154.04 {time_to_server,max}: 728.917 {time_to_client,avg}: 6218.081375635741 {time_to_server,avg}: 58.365337024422914 bytes: 48660 packets: 1972 {bytes,per_sec}: 4866 {packets,per_sec}: 197 From vychodil.hynek Mon Oct 6 12:11:47 2008 From: vychodil.hynek (Hynek Vychodil) Date: Mon, 6 Oct 2008 12:11:47 +0200 Subject: [erlang-questions] Erlang external binary term format In-Reply-To: <19830881.post@talk.nabble.com> References: <19830781.post@talk.nabble.com> <19830881.post@talk.nabble.com> Message-ID: <20081006101148.335C22407D@relay.gooddata.com> Just RTM http://www.erlang.org/doc/apps/erts/erl_ext_dist.html#8 On Mon, Oct 6, 2008 at 3:29 AM, deepblue_other wrote: > > for example > one day I was looking at the term_to_binary() output of > {binaries,"are",useful} > and it was: > > 131,104,3,100,0,8,98,105,110,97,114,105,101,115,107,0,3,97,114,101,100,0,6,117,115,101,102,117,108 > > so with a little experimentation with other tuples I got these rules so > far: > 131,104 - this means that its a tuple > 3 - this means that it has 3 terms > 100 and 107 - type code - in this case 100 stands for atoms, and 107 stands > for strings > 0 - is the separator between the "type code"(name I gave it > just now ;) ) and the actual ASCII sequence > 8 and 3(again) and 6 - these indicate the length of the binary sequence > (number of ASCII characters in this case > > so: > binaries - 100(type code),0,8(byte length),98,105,110,97,114,105,101,115 > "are" - 107(type code),0,3(byte length),97,114,101 > useful - 100(type code),0,6(byte length),117,115,101,102,117,108 > > this just explains a limited set, doesnt go into lists... > I could be wrong, but the rules seem to match up other examples as well > > thanks > > deepblue_other wrote: > > > > term_to_binary() outputs a binary. > > what is the format of that binary? I would like to create a > > "unpacker/packer" for that format in ActionScript3, and avoid the use of > > XML (which Im using now for Flash-to-Erlang) communication altogether. it > > would be faster, less code, and much more efficient from the bandwidth > > point of view. > > > > is there a document someplace that gives the byte layout maybe? > > thank you > > > > -- > View this message in context: > http://www.nabble.com/Erlang-external-binary-term-format-tp19830781p19830881.html > Sent from the Erlang Questions mailing list archive at Nabble.com. > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -- --Hynek (Pichi) Vychodil -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081006/9b2616cb/attachment.html From cktgatb Mon Oct 6 17:21:56 2008 From: cktgatb (deepblue_other) Date: Mon, 6 Oct 2008 08:21:56 -0700 (PDT) Subject: [erlang-questions] wierd "function not used" problem - code included In-Reply-To: <19830744.post@talk.nabble.com> References: <19826465.post@talk.nabble.com> <19827659.post@talk.nabble.com> <19827696.post@talk.nabble.com> <19827720.post@talk.nabble.com> <19828568.post@talk.nabble.com> <19829936.post@talk.nabble.com> <19830744.post@talk.nabble.com> Message-ID: <19840082.post@talk.nabble.com> Edwin Fine wrote: > > > deepblue_other wrote: >> >> so when I want to use spawn_link() with a named function that function >> has to be exported? >> same stands for regular spawn()? >> > Yes, if you use a spawn that takes Module, Function, Args, like spawn/3, > spawn/4, spawn_link/3, spawn_link/4,.... Or apply/3. And so on. > > In general if you provide a so-called "MFA" (Module, Func, Args) to a > function, the Func has to be exported from Module, even if the Func is > only for internal use within Module. > > It's important to know that the shell is your friend. It's critical to try > out little pieces of code in the shell to see if they work the way you > expect. For example, if you wanted to see if spawn could see your > data_process function, you could have tried it in the shell (I'm passing > the atom 'junk' instead of a real socket because I know the call will fail > because it's not exported, so the socket is not needed): > > 1> c(tcp_manager). > ./tcp_manager.erl:33: Warning: function data_process/2 is unused > {ok,tcp_manager} > 2> spawn(tcp_manager, data_process, [junk, []]). > <0.40.0> > 3> > =ERROR REPORT==== 5-Oct-2008::20:49:23 === > Error in process <0.40.0> with exit value: > {undef,[{tcp_manager,data_process,[junk,[]]}]} > > deepblue_other wrote: >> >> just a side question: >> once a certain "receive" configuration is set for a process it can never >> be changed to another "receive" configuration? it just popped in my head >> here when you said that i can inline the error "receive". >> > > I perhaps did not make myself clear. What I meant by saying you could > inline it is that I didn't see the value of writing > > Fun = fun() -> do_something(), do_something_else() end, > Fun(). > > That's the same as writing > > do_something(), > do_something_else() > no I understood what you wanted to say, I just had a case in my mind where for example a "receive configuration" is active for a process, and a message that matches comes in, and the clause starts executing its expressions and one of the expressions calls another function that within it contains another "receive configuration" - the new configuration would now be active, and the old one would stop? also the expressions listed bellow a "receive configuration" are executed even though the "receive" essentially blocks the process in waiting state? as you can tell Im slightly confused as to how the "receive" affects the present/future activity of a process Edwin Fine wrote: > > It is better in this case to put the code into a separate function. > Better, because you can hot-swap the code and change that function. > > There's an excellent article about hot code swapping > http://http://spawnlink.com/articles/rules-of-hot-code-swapping/ here . > I will read this through now Edwin Fine wrote: > > > >> %----------------------------------------------- >> Listen_for_errors = >> fun() -> >> io:format("listening started~n"), >> receive >> {'EXIT', Pid, Why} -> >> io:format("~p exited because:~p", [Pid,Why]); >> Other -> >> io:format("Other:~p~n", [Other]) >> end >> end, >> Listen_for_errors(), >> %----------------------------------------------- >> > Finally, I'm not sure what Listen_for_errors() is supposed to do. It's > just going to sit there forever in the receive, waiting for the first > message that is sent (or en exit signal), and print it out (thus throwing > it away), and return. What did you want it to do? > Listen_for_errors() was meant to catch the errors that were produced because I didnt export the function I used in spawn_link() :) and just to see if the data was coming in from the client. thanks Edwin -- View this message in context: http://www.nabble.com/wierd-%22function-not-used%22-problem---code-included-tp19826465p19840082.html Sent from the Erlang Questions mailing list archive at Nabble.com. From kenneth.lundin Mon Oct 6 12:56:58 2008 From: kenneth.lundin (Kenneth Lundin) Date: Mon, 6 Oct 2008 12:56:58 +0200 Subject: [erlang-questions] Erlang external binary term format In-Reply-To: <19830881.post@talk.nabble.com> References: <19830781.post@talk.nabble.com> <19830881.post@talk.nabble.com> Message-ID: You find the documentation of the Erlang external term format here: http://www.erlang.org/doc/apps/erts/erl_ext_dist.html#8 (It is chapter 8 of the ERTS Users Guide) /Kenneth Erlang/OTP tema, Ericsson On Mon, Oct 6, 2008 at 3:29 AM, deepblue_other wrote: > > for example > one day I was looking at the term_to_binary() output of > {binaries,"are",useful} > and it was: > 131,104,3,100,0,8,98,105,110,97,114,105,101,115,107,0,3,97,114,101,100,0,6,117,115,101,102,117,108 > > so with a little experimentation with other tuples I got these rules so far: > 131,104 - this means that its a tuple > 3 - this means that it has 3 terms > 100 and 107 - type code - in this case 100 stands for atoms, and 107 stands > for strings > 0 - is the separator between the "type code"(name I gave it > just now ;) ) and the actual ASCII sequence > 8 and 3(again) and 6 - these indicate the length of the binary sequence > (number of ASCII characters in this case > > so: > binaries - 100(type code),0,8(byte length),98,105,110,97,114,105,101,115 > "are" - 107(type code),0,3(byte length),97,114,101 > useful - 100(type code),0,6(byte length),117,115,101,102,117,108 > > this just explains a limited set, doesnt go into lists... > I could be wrong, but the rules seem to match up other examples as well > > thanks > > deepblue_other wrote: >> >> term_to_binary() outputs a binary. >> what is the format of that binary? I would like to create a >> "unpacker/packer" for that format in ActionScript3, and avoid the use of >> XML (which Im using now for Flash-to-Erlang) communication altogether. it >> would be faster, less code, and much more efficient from the bandwidth >> point of view. >> >> is there a document someplace that gives the byte layout maybe? >> thank you >> > > -- > View this message in context: http://www.nabble.com/Erlang-external-binary-term-format-tp19830781p19830881.html > Sent from the Erlang Questions mailing list archive at Nabble.com. > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From bengt.kleberg Mon Oct 6 11:20:46 2008 From: bengt.kleberg (Bengt Kleberg) Date: Mon, 06 Oct 2008 11:20:46 +0200 Subject: [erlang-questions] Erlang timer program - feedback please In-Reply-To: <4d775bd70810031152g57c4f217vd181a8b3db3248db@mail.gmail.com> References: <4d775bd70810031152g57c4f217vd181a8b3db3248db@mail.gmail.com> Message-ID: <1223284849.17611.28.camel@seasc0642.dyn.rnd.as.sw.ericsson.se> Greetings, If you want to call/send at a regular interval you might want to use timer:apply_interval/4 or timer:send_interval/2 in http://erlang.org/doc/man/timer.html bengt On Fri, 2008-10-03 at 11:52 -0700, Sean Payne wrote: > I am hoping someone with more Erlang experience than me could give me > some feedback on the timer code below. > > I am using erlang:start_timer and tail recursion with a paused state > and a running state to create a little simulation > * world:init(). inits the sim > * world:run(). starts the updates (right now updates just print out > "updating") > * world:pause(). pauses the updates > * world:destroy(). shuts it down > > So my questions are: > 1) Is there a better way (timer wise) to do this. I suspect that the > way I am using the timer that my update_now will not be called at the > right frequency because of the delay between when the event fires and > when the next event is scheduled. > > 2) Is there a better way Erlang wise to do something like this. I am > new to Erlang, so I am curious if this is the approach that someone > with more experience would take. Is this how you would write > this????? > > 3) Are there any bugs or leaks? ie am I using Tail recursion > correctly? (every time I pause or unpause the program, am I going > deeper into the stack?) > > Thanks, > > Sean > > ========================================= > -module(world). > > %% External interfaces > %% world:init sets up the world (into the paused state) > %% world:run starts the timers and updates every UPDATE_INTERVAL > %% world:stop pauses the world > %% world:destroy destroys the world > -export([init/0]). > -export([run/0]). > -export([stop/0]). > -export([destroy/0]). > > %% internal functions but must be exported to receive events from > erlang:start_timer > -export([handle_events_while_stopped/0]). > -export([handle_events_while_running/0]). > > -define(UPDATE_INTERVAL,1000). > > handle_events_while_stopped() -> > receive > finished-> > io:format("world is finished~n", []); > run-> > io:format("world is running~n", []), > erlang:start_timer(?UPDATE_INTERVAL, self(), update_now), > handle_events_while_running() > end. > > handle_events_while_running() -> > receive > finished-> > io:format("world is finished~n", []); > stop-> > io:format("world is stopping~n", []), > handle_events_while_stopped(); > {timeout, _ , update_now} -> > io:format("updating~n", []), > erlang:start_timer(?UPDATE_INTERVAL, self(), update_now), > handle_events_while_running() > end. > > > init() -> > register(world, spawn(world, handle_events_while_stopped,[])). > > run()-> > world ! run. > > stop()-> > world ! stop. > > destroy()-> > world ! finished. > > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions From joelr1 Mon Oct 6 14:36:33 2008 From: joelr1 (Joel Reymont) Date: Mon, 6 Oct 2008 13:36:33 +0100 Subject: [erlang-questions] latency of smp vs non-smp + optimizing throughput In-Reply-To: <0BD13575-3DF8-4AFC-BE33-D45B09D4D7A9@gmail.com> References: <0BD13575-3DF8-4AFC-BE33-D45B09D4D7A9@gmail.com> Message-ID: I seem to do much better running 3 non-SMP VMs (-smp disable) on my Mac, at least 500 games run to completion without any drastic increases in latency. SMP vs non-SMP stats are at the bottom of this email but briefly looking at the last statistics dump: SMP disabled: {time_to_client,avg}: 224.20649573953042 {time_to_server,avg}: 71.4781241171356 SMP enabled: {time_to_client,avg}: 3586.21374521735 {time_to_server,avg}: 0.345146548308556 I thought that the increase in outgoing latency is due to the sheer amount of data that I'm pumping out. For example, every 10 seconds I get this much data in bytes_in: 793628 {bytes_in,per_sec}: 79362 packets_in: 32108 {packets_in,per_sec}: 3210 which gives decent incoming latency {time_to_server,min}: 23.144 {time_to_server,avg}: 71.4781241171356 {time_to_server,max}: 488.238 I'm pumping out almost as much data, though bytes_out: 778418 {bytes_out,per_sec}: 77841 but in twice as many packets. packets_out: 63074 {packets_out,per_sec}: 6307 This gives me a much higher outgoing latency that I'm still scratching my head over. {time_to_client,min}: 34.8 {time_to_client,avg}: 224.20649573953042 {time_to_client,max}: 2599.91 Any suggestions on how to optimize this? Thanks, Joel --- SMP disabled --- Erlang (BEAM) emulator version 5.6.3 [source] [64-bit] [async-threads: 0] [kernel-poll:true] (1)2> dmb:test(500). gateway:start('1', 4000, 500000) Waiting for game servers... Starting a port server on 4000... Simulating gameplay with 500 games... 50 games started, 262 players 100 games started, 504 players 150 games started, 743 players 200 games started, 1019 players 250 games started, 1288 players 300 games started, 1529 players 350 games started, 1766 players 400 games started, 2057 players 450 games started, 2304 players 500 games started, 2562 players dmb: 500 games launching simultaneously dmb: waiting for games to end... =INFO REPORT==== 6-Oct-2008::13:21:03 === module: stats elapsed: 10.000171 bytes_in: 146366 bytes_out: 46116 packets_in: 8186 packets_out: 5124 {bytes_in,per_sec}: 14636 {bytes_out,per_sec}: 4611 {packets_in,per_sec}: 818 {packets_out,per_sec}: 512 {time_to_client,min}: 0.39 {time_to_server,min}: 0.053 {time_to_client,max}: 4.65 {time_to_server,max}: 3.243 {time_to_client,avg}: 0.7572145936482696 {time_to_server,avg}: 0.2872718335693714 =INFO REPORT==== 6-Oct-2008::13:21:13 === module: stats elapsed: 10.000046 bytes_in: 113721 bytes_out: 446136 packets_in: 4797 packets_out: 30062 {bytes_in,per_sec}: 11372 {bytes_out,per_sec}: 44613 {packets_in,per_sec}: 479 {packets_out,per_sec}: 3006 {time_to_client,min}: 0.29 {time_to_server,min}: 0.085 {time_to_client,max}: 31.137 {time_to_server,max}: 37.724 {time_to_client,avg}: 17.673999912193082 {time_to_server,avg}: 9.69423139935136 =INFO REPORT==== 6-Oct-2008::13:21:23 === module: stats elapsed: 9.999948 bytes_in: 486797 bytes_out: 220674 packets_in: 20351 packets_out: 15110 {bytes_in,per_sec}: 48679 {bytes_out,per_sec}: 22067 {packets_in,per_sec}: 2035 {packets_out,per_sec}: 1511 {time_to_client,min}: 0.466 {time_to_server,min}: 1.573 {time_to_client,max}: 39.079 {time_to_server,max}: 61.043 {time_to_client,avg}: 0.9661870246546748 {time_to_server,avg}: 1.7370862806690366 =INFO REPORT==== 6-Oct-2008::13:21:33 === module: stats elapsed: 10.000047 bytes_in: 42489 bytes_out: 1827059 packets_in: 1713 packets_out: 148182 {bytes_in,per_sec}: 4248 {bytes_out,per_sec}: 182705 {packets_in,per_sec}: 171 {packets_out,per_sec}: 14818 {time_to_client,min}: 0.241 {time_to_server,min}: 0.063 {time_to_client,max}: 216.895 {time_to_server,max}: 35.445 {time_to_client,avg}: 90.84005908047558 {time_to_server,avg}: 9.594852014216947 =INFO REPORT==== 6-Oct-2008::13:21:43 === module: stats elapsed: 9.999926 bytes_in: 186974 bytes_out: 1309921 packets_in: 7550 packets_out: 109166 {bytes_in,per_sec}: 18697 {bytes_out,per_sec}: 130993 {packets_in,per_sec}: 755 {packets_out,per_sec}: 10916 {time_to_client,min}: 13.339 {time_to_server,min}: 4.094 {time_to_client,max}: 548.193 {time_to_server,max}: 168.099 {time_to_client,avg}: 257.6465068927692 {time_to_server,avg}: 40.70231906170637 dmb: exited successfully, 53.110242 seconds elapsed ok (1)3> halt(). =INFO REPORT==== 6-Oct-2008::13:21:53 === module: stats elapsed: 10.000018 bytes_in: 793628 bytes_out: 778418 packets_in: 32108 packets_out: 63074 {bytes_in,per_sec}: 79362 {bytes_out,per_sec}: 77841 {packets_in,per_sec}: 3210 {packets_out,per_sec}: 6307 {time_to_client,min}: 34.8 {time_to_server,min}: 23.144 {time_to_client,max}: 2599.91 {time_to_server,max}: 488.238 {time_to_client,avg}: 224.20649573953042 {time_to_server,avg}: 71.4781241171356 --- SMP enabled --- Doesn't run through and is made to crash on a timeout. Erlang (BEAM) emulator version 5.6.3 [source] [64-bit] [smp:8] [async- threads:0] [kernel-poll:true] (1)2> dmb:test(500). gateway:start('1', 4000, 500000) Waiting for game servers... Starting a port server on 4000... Simulating gameplay with 500 games... 50 games started, 262 players 100 games started, 504 players 150 games started, 743 players 200 games started, 1019 players 250 games started, 1288 players 300 games started, 1529 players 350 games started, 1766 players 400 games started, 2057 players 450 games started, 2304 players 500 games started, 2562 players dmb: 500 games launching simultaneously dmb: waiting for games to end... =INFO REPORT==== 6-Oct-2008::13:26:56 === module: stats elapsed: 10.001047 bytes_in: 129677 bytes_out: 40914 packets_in: 7252 packets_out: 4546 {bytes_in,per_sec}: 12966 {bytes_out,per_sec}: 4090 {packets_in,per_sec}: 725 {packets_out,per_sec}: 454 {time_to_client,min}: 0.479 {time_to_server,min}: 0.064 {time_to_client,max}: 2.798 {time_to_server,max}: 2.383 {time_to_client,avg}: 1.0302147870344318 {time_to_server,avg}: 1.0730058206685198 =INFO REPORT==== 6-Oct-2008::13:27:06 === module: stats elapsed: 9.999979 bytes_in: 73372 bytes_out: 119961 packets_in: 3343 packets_out: 8176 {bytes_in,per_sec}: 7337 {bytes_out,per_sec}: 11996 {packets_in,per_sec}: 334 {packets_out,per_sec}: 817 {time_to_client,min}: 0.556 {time_to_server,min}: 0.067 {time_to_client,max}: 207.146 {time_to_server,max}: 60.546 {time_to_client,avg}: 114.43896301514758 {time_to_server,avg}: 0.8372796687202076 =INFO REPORT==== 6-Oct-2008::13:27:16 === module: stats elapsed: 9.998979 bytes_in: 543835 bytes_out: 552051 packets_in: 22739 packets_out: 37574 {bytes_in,per_sec}: 54389 {bytes_out,per_sec}: 55210 {packets_in,per_sec}: 2274 {packets_out,per_sec}: 3757 {time_to_client,min}: 26.731 {time_to_server,min}: 0.067 {time_to_client,max}: 2600.522 {time_to_server,max}: 430.95 {time_to_client,avg}: 281.00073907216733 {time_to_server,avg}: 0.7417702616026968 =INFO REPORT==== 6-Oct-2008::13:27:26 === module: stats elapsed: 10.00179 bytes_in: 333568 bytes_out: 1035862 packets_in: 13460 packets_out: 81032 {bytes_in,per_sec}: 33350 {bytes_out,per_sec}: 103567 {packets_in,per_sec}: 1345 {packets_out,per_sec}: 8101 {time_to_client,min}: 0.979 {time_to_server,min}: 0.069 {time_to_client,max}: 3687.48 {time_to_server,max}: 596.026 {time_to_client,avg}: 622.5489355064024 {time_to_server,avg}: 1.83386123075884 ** exception error: no case clause matching noconnection in function dmb:wait_for_games/1 (1)3> =INFO REPORT==== 6-Oct-2008::13:27:36 === module: stats elapsed: 9.998224 bytes_in: 153581 bytes_out: 99958 packets_in: 6205 packets_out: 8446 {bytes_in,per_sec}: 15360 {bytes_out,per_sec}: 9997 {packets_in,per_sec}: 620 {packets_out,per_sec}: 844 {time_to_client,min}: 298.654 {time_to_server,min}: 0.078 {time_to_client,max}: 5431.219 {time_to_server,max}: 794.497 {time_to_client,avg}: 3586.21374521735 {time_to_server,avg}: 0.345146548308556 --- http://wagerlabs.com From joelr1 Mon Oct 6 15:34:01 2008 From: joelr1 (Joel Reymont) Date: Mon, 6 Oct 2008 14:34:01 +0100 Subject: [erlang-questions] latency of smp vs non-smp + optimizing throughput In-Reply-To: References: <0BD13575-3DF8-4AFC-BE33-D45B09D4D7A9@gmail.com> Message-ID: <3598ECD4-8216-43F1-9719-983D33557F78@gmail.com> The good news here is that Solaris/Opteron (Nevada) doesn't seem to break a sweat. Note that SMP is disabled. Erlang (BEAM) emulator version 5.6.4 [source] [async-threads:0] [hipe] [kernel-poll:true] --- 3k games, 15K players, 3 VMs --- (1)2> dmb:test(3000). gateway:start('1', 4000, 500000) Waiting for game servers... Starting a port server on 4000... Simulating gameplay with 3000 games... 50 games started, 262 players ... 3000 games started, 15115 players dmb: 3000 games launching simultaneously dmb: waiting for games to end... =INFO REPORT==== 6-Oct-2008::13:24:59 === module: stats elapsed: 10.000873 bytes_in: 68767 bytes_out: 21636 packets_in: 3842 packets_out: 2404 {bytes_in,per_sec}: 6876 {bytes_out,per_sec}: 2163 {packets_in,per_sec}: 384 {packets_out,per_sec}: 240 {time_to_client,min}: 0.328 {time_to_server,min}: -0.153 {time_to_client,max}: 15.524 {time_to_server,max}: 7.772 {time_to_client,avg}: 0.9502826468283405 {time_to_server,avg}: 0.5327277638966361 =INFO REPORT==== 6-Oct-2008::13:25:09 === module: stats elapsed: 10.001858 bytes_in: 282707 bytes_out: 88956 packets_in: 15795 packets_out: 9884 {bytes_in,per_sec}: 28265 {bytes_out,per_sec}: 8893 {packets_in,per_sec}: 1579 {packets_out,per_sec}: 988 {time_to_client,min}: 0.342 {time_to_server,min}: -0.154 {time_to_client,max}: 32.193 {time_to_server,max}: 9.188 {time_to_client,avg}: 0.5440724004487766 {time_to_server,avg}: 0.16925260605105938 =INFO REPORT==== 6-Oct-2008::13:25:19 === module: stats elapsed: 9.998239 bytes_in: 1017300 bytes_out: 1076952 packets_in: 43558 packets_out: 73806 {bytes_in,per_sec}: 101747 {bytes_out,per_sec}: 107714 {packets_in,per_sec}: 4356 {packets_out,per_sec}: 7381 {time_to_client,min}: 0.273 {time_to_server,min}: -0.166 {time_to_client,max}: 17.486 {time_to_server,max}: 36.317 {time_to_client,avg}: 0.8381414371981343 {time_to_server,avg}: -0.06003086403873219 =INFO REPORT==== 6-Oct-2008::13:25:29 === module: stats elapsed: 9.999059 bytes_in: 941158 bytes_out: 2475950 packets_in: 39362 packets_out: 190330 {bytes_in,per_sec}: 94124 {bytes_out,per_sec}: 247618 {packets_in,per_sec}: 3936 {packets_out,per_sec}: 19034 {time_to_client,min}: 0.27 {time_to_server,min}: -0.167 {time_to_client,max}: 140.496 {time_to_server,max}: 13.837 {time_to_client,avg}: 85.4554748230033 {time_to_server,avg}: 3.818637893852275 =INFO REPORT==== 6-Oct-2008::13:25:39 === module: stats elapsed: 10.001362 bytes_in: 537800 bytes_out: 3835109 packets_in: 22175 packets_out: 309980 {bytes_in,per_sec}: 53772 {bytes_out,per_sec}: 383458 {packets_in,per_sec}: 2217 {packets_out,per_sec}: 30993 {time_to_client,min}: 6.174 {time_to_server,min}: 0.252 {time_to_client,max}: 1159.445 {time_to_server,max}: 54.943 {time_to_client,avg}: 223.2975698054841 {time_to_server,avg}: 22.01449211439593 =INFO REPORT==== 6-Oct-2008::13:25:49 === module: stats elapsed: 9.998972 bytes_in: 791081 bytes_out: 2707910 packets_in: 32433 packets_out: 225746 {bytes_in,per_sec}: 79116 {bytes_out,per_sec}: 270818 {packets_in,per_sec}: 3243 {packets_out,per_sec}: 22576 {time_to_client,min}: 33.944 {time_to_server,min}: 0.533 {time_to_client,max}: 2487.903 {time_to_server,max}: 136.146 {time_to_client,avg}: 600.7879700669516 {time_to_server,avg}: 20.330412830951946 =INFO REPORT==== 6-Oct-2008::13:25:59 === module: stats elapsed: 10.000539 bytes_in: 74843 bytes_out: 2826243 packets_in: 3055 packets_out: 231956 {bytes_in,per_sec}: 7483 {bytes_out,per_sec}: 282609 {packets_in,per_sec}: 305 {packets_out,per_sec}: 23194 {time_to_client,min}: 76.3 {time_to_server,min}: 0.758 {time_to_client,max}: 2539.293 {time_to_server,max}: 114.08 {time_to_client,avg}: 1168.0286129495837 {time_to_server,avg}: 4.338520242410239 =INFO REPORT==== 6-Oct-2008::13:26:09 === module: stats elapsed: 9.999128 bytes_in: 2258335 bytes_out: 887220 packets_in: 92719 packets_out: 71770 {bytes_in,per_sec}: 225853 {bytes_out,per_sec}: 88729 {packets_in,per_sec}: 9272 {packets_out,per_sec}: 7177 {time_to_client,min}: 74.793 {time_to_server,min}: -0.16 {time_to_client,max}: 6072.688 {time_to_server,max}: 403.202 {time_to_client,avg}: 2467.0929211869234 {time_to_server,avg}: 21.581616260229122 =INFO REPORT==== 6-Oct-2008::13:26:19 === module: stats elapsed: 10.00713 bytes_in: 2868537 bytes_out: 168167 packets_in: 118195 packets_out: 13846 {bytes_in,per_sec}: 286649 {bytes_out,per_sec}: 16804 {packets_in,per_sec}: 11811 {packets_out,per_sec}: 1383 {time_to_client,min}: 141.216 {time_to_server,min}: -0.162 {time_to_client,max}: 9914.637 {time_to_server,max}: 527.446 {time_to_client,avg}: 796.8525357953445 {time_to_server,avg}: 22.936007665596 =INFO REPORT==== 6-Oct-2008::13:26:29 === module: stats elapsed: 9.992855 bytes_in: 2117299 bytes_out: 549453 packets_in: 89253 packets_out: 40298 {bytes_in,per_sec}: 211881 {bytes_out,per_sec}: 54984 {packets_in,per_sec}: 8931 {packets_out,per_sec}: 4032 {time_to_client,min}: 11.262 {time_to_server,min}: -0.162 {time_to_client,max}: 10542.49 {time_to_server,max}: 439.312 {time_to_client,avg}: 237.57952461078088 {time_to_server,avg}: 94.565093206288 =INFO REPORT==== 6-Oct-2008::13:26:39 === module: stats elapsed: 10.000009 bytes_in: 1310469 bytes_out: 1931419 packets_in: 56212 packets_out: 152378 {bytes_in,per_sec}: 131046 {bytes_out,per_sec}: 193141 {packets_in,per_sec}: 5621 {packets_out,per_sec}: 15237 {time_to_client,min}: 0.271 {time_to_server,min}: 13.38 {time_to_client,max}: 6630.608 {time_to_server,max}: 505.429 {time_to_client,avg}: 5.189399196632146 {time_to_server,avg}: 43.817916713631014 =INFO REPORT==== 6-Oct-2008::13:26:49 === module: stats elapsed: 9.999995 bytes_in: 690046 bytes_out: 2840243 packets_in: 30002 packets_out: 227816 {bytes_in,per_sec}: 69004 {bytes_out,per_sec}: 284024 {packets_in,per_sec}: 3000 {packets_out,per_sec}: 22781 {time_to_client,min}: 0.281 {time_to_server,min}: 19.745 {time_to_client,max}: 63.059 {time_to_server,max}: 506.526 {time_to_client,avg}: 3.4162563678436983 {time_to_server,avg}: 32.55984930907259 =INFO REPORT==== 6-Oct-2008::13:26:59 === module: stats elapsed: 10.003134 bytes_in: 518215 bytes_out: 2372858 packets_in: 22845 packets_out: 193438 {bytes_in,per_sec}: 51805 {bytes_out,per_sec}: 237211 {packets_in,per_sec}: 2283 {packets_out,per_sec}: 19337 {time_to_client,min}: 0.27 {time_to_server,min}: 13.644 {time_to_client,max}: 72.208 {time_to_server,max}: 289.966 {time_to_client,avg}: 1.0623046789650372 {time_to_server,avg}: 28.797672193416293 =INFO REPORT==== 6-Oct-2008::13:27:09 === module: stats elapsed: 9.997725 bytes_in: 1239798 bytes_out: 1145689 packets_in: 56628 packets_out: 93128 {bytes_in,per_sec}: 124008 {bytes_out,per_sec}: 114594 {packets_in,per_sec}: 5664 {packets_out,per_sec}: 9314 {time_to_client,min}: 0.262 {time_to_server,min}: -0.168 {time_to_client,max}: 81.195 {time_to_server,max}: 253.462 {time_to_client,avg}: 8.403465667253972 {time_to_server,avg}: 2.3821230459554026 =INFO REPORT==== 6-Oct-2008::13:27:19 === module: stats elapsed: 10.000059 bytes_in: 4330839 bytes_out: 804560 packets_in: 183647 packets_out: 63266 {bytes_in,per_sec}: 433081 {bytes_out,per_sec}: 80455 {packets_in,per_sec}: 18364 {packets_out,per_sec}: 6326 {time_to_client,min}: 0.252 {time_to_server,min}: -0.168 {time_to_client,max}: 87.52 {time_to_server,max}: 122.569 {time_to_client,avg}: 4.041418440137954 {time_to_server,avg}: 41.888633391776644 =INFO REPORT==== 6-Oct-2008::13:27:29 === module: stats elapsed: 9.999943 bytes_in: 6079331 bytes_out: 1207405 packets_in: 257496 packets_out: 95114 {bytes_in,per_sec}: 607936 {bytes_out,per_sec}: 120741 {packets_in,per_sec}: 25749 {packets_out,per_sec}: 9511 {time_to_client,min}: 0.248 {time_to_server,min}: -0.168 {time_to_client,max}: 110.687 {time_to_server,max}: 160.911 {time_to_client,avg}: 0.6254370271594177 {time_to_server,avg}: 0.6895430481677953 =INFO REPORT==== 6-Oct-2008::13:27:39 === module: stats elapsed: 9.99912 bytes_in: 2437108 bytes_out: 1673955 packets_in: 102193 packets_out: 137242 {bytes_in,per_sec}: 243732 {bytes_out,per_sec}: 167410 {packets_in,per_sec}: 10220 {packets_out,per_sec}: 13725 {time_to_client,min}: 0.23 {time_to_server,min}: -0.17 {time_to_client,max}: 272.111 {time_to_server,max}: 75.171 {time_to_client,avg}: 1.0046702454518566 {time_to_server,avg}: -0.08508062985883734 dmb: exited successfully, 164.797657 seconds elapsed ok (1)3> =INFO REPORT==== 6-Oct-2008::13:27:49 === module: stats elapsed: 10.007192 bytes_in: 448990 bytes_out: 439782 packets_in: 18794 packets_out: 36034 {bytes_in,per_sec}: 44866 {bytes_out,per_sec}: 43946 {packets_in,per_sec}: 1878 {packets_out,per_sec}: 3600 {time_to_client,min}: 0.273 {time_to_server,min}: -0.169 {time_to_client,max}: 12.465 {time_to_server,max}: 8.763 {time_to_client,avg}: 5.224798551005151 {time_to_server,avg}: 0.09153370462824446 From greg.burri Mon Oct 6 16:08:48 2008 From: greg.burri (Greg Burri) Date: Mon, 6 Oct 2008 16:08:48 +0200 Subject: [erlang-questions] Get a range of tuples from a Mnesia table In-Reply-To: <6c2563b20810041111t401ebb0fh5482d383438f0b8b@mail.gmail.com> References: <60ed8a460810040919qcf9dd37m994bbf6932f18cc0@mail.gmail.com> <6c2563b20810041111t401ebb0fh5482d383438f0b8b@mail.gmail.com> Message-ID: <60ed8a460810060708x61bf8799xf6a399b0f525393a@mail.gmail.com> Thanks for you reply. I haven't try yet but I keep your answer for later use. On Sat, Oct 4, 2008 at 8:11 PM, Edwin Fine wrote: > Looking through the docs, I see that if you are using an mnesia table that > is ram_copies or disc_copies, you can do certain fast operations on the > associated ets table. One such operation (which is recommended only for > debugging, but what the heck) is ets:slot(Tab, I), which returns the I'th > record in the table. So maybe you could find a way to do that on the ETS > table that Mnesia is using, perhaps via the mnesia:ets() function. I have > never tried this so it's just a guess. This is also kind of a hack but other > than reading through the mnesia code, I can't locate something better. Maybe > one of the real Mnesia gurus will have an idea. > > 2008/10/4 Greg Burri > >> Hi, >> I want to retrieve N tuple with an offset O from the end of a table. N and >> O are integer(). I consider that the acces is based on an ordered table. >> >> Here is an example, I have such tuples in my table t : >> [{t, 1, _}, >> {t, 2, _}, >> {t, 3, _}, >> {t, 4, _}, >> {t, 5, _}, >> {t, 6, _}, >> {t, 7, _}] >> >> For N=2 and O=3 the result will be : >> [{t, 4, _}, {t, 5, _}] >> >> For now I have to use an ordered_set table and the functions mnesia:last/1 >> and mnesia:prev/2, it works but the complexity is O(O). If I have to get >> some tuple from the middle of the table it will take long time. >> Is there an another solution than mine ? >> >> Second question : How change the type of a table from set to ordered_set >> on an existing table ? >> >> >> /Greg Burri >> >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions >> http://www.erlang.org/mailman/listinfo/erlang-questions >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081006/d024148e/attachment-0001.html From greg.burri Mon Oct 6 16:17:55 2008 From: greg.burri (Greg Burri) Date: Mon, 6 Oct 2008 16:17:55 +0200 Subject: [erlang-questions] Convert a Mnesia "set" table to an "ordered_set" Message-ID: <60ed8a460810060717i67d6231dxbe28918fc751845@mail.gmail.com> Hi, I already ask this question but it was hided into a mail about something else. Is there a way to convert a mnesia table which has the type "set" to a "ordered_set" one ? For the moment I use "mnesia:backup/1" then I recreate my table with the "ordered_set" type and I call "mnesia:restore/2" to retrieve my data. It's a bit ugly... it isn't ? /Greg Burri -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081006/e4c809bb/attachment-0001.html From kenneth.lundin Mon Oct 6 16:49:52 2008 From: kenneth.lundin (Kenneth Lundin) Date: Mon, 6 Oct 2008 16:49:52 +0200 Subject: [erlang-questions] Erlang Course on Web-Site (IP Rights) In-Reply-To: <48E9A2AB.5090907@adam.com.au> References: <48E9A2AB.5090907@adam.com.au> Message-ID: Hi, The IP for the course is owned by Ericsson AB, I will add the Copyright notice which should have been there from the beginning. The rights and restrictions should be defined by the Erlang Public License which I think is a suitable license to be used for both the code and the documentation of Erlang/OTP as well as other publications created by the Erlang/OTP group at Ericssoon. /Kenneth Erlang/OTP team , Ericsson On Mon, Oct 6, 2008 at 7:31 AM, David Lloyd wrote: > > Hi There, > > > The Erlang Course: > > * http://www.erlang.org/course/course.html > > ...doesn't have any obvious attribution as to who or what legal entity > owns the copyright and other rights to it. > > Does anyone know who the IP owner actually is and if there are any > specific restrictions on its use (eg. not in a commercial setting)? > > > DSL > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From cktgatb Mon Oct 6 17:05:58 2008 From: cktgatb (deepblue_other) Date: Mon, 6 Oct 2008 08:05:58 -0700 (PDT) Subject: [erlang-questions] Erlang external binary term format In-Reply-To: <19835272.post@talk.nabble.com> References: <19830781.post@talk.nabble.com> <19835272.post@talk.nabble.com> Message-ID: <19839752.post@talk.nabble.com> ah, sorry about that thanks Edwin Fine wrote: > > > deepblue_other wrote: >> >> term_to_binary() outputs a binary. >> what is the format of that binary? >> is there a document someplace that gives the byte layout maybe? >> > This is what you want: http://erlang.org/doc/apps/erts/erl_ext_dist.html > Erlang external term format documentation > > You might want to search the Erlang mailing list before asking questions. > A lot of your questions may be answered already. For example, a search > using the words "external term format" found the answer to your question > in seconds using http://www.erlang.org/faq.html Search the Erlang Mailing > Lists > -- View this message in context: http://www.nabble.com/Erlang-external-binary-term-format-tp19830781p19839752.html Sent from the Erlang Questions mailing list archive at Nabble.com. From dgud Mon Oct 6 09:50:12 2008 From: dgud (Dan Gudmundsson) Date: Mon, 06 Oct 2008 09:50:12 +0200 Subject: [erlang-questions] Request to add md4 to crypto module In-Reply-To: References: <200810030329.09362.alexander.uvarov@gmail.com> <48E5EF23.3050708@erix.ericsson.se> Message-ID: <48E9C334.70802@erix.ericsson.se> See the thread: http://www.erlang.org/pipermail/erlang-bugs/2008-September/000989.html /Dan Will wrote: > Hi Dan, > > Glad to hear you're in the midst of work on crypto! I submitted patches > a long time ago to add MD5 and SHA1 signing and verification with RSA > keys. I'd love to see this included in crypto. > > http://article.gmane.org/gmane.comp.lang.erlang.patches/151 > > Thanks, > Will > > On Fri, Oct 3, 2008 at 3:08 AM, Dan Gudmundsson > wrote: > > You don't have to write (in my mind) an EEP for adding things in a > library, > EEP is for language changes or other major erlang changes. > > Send a patch to erlang-patches, and if we thinks it's ok and have > time we will add it. > > /Dan "Currently adding things to crypto" > > Alexander wrote: > > On Thursday 02 October 2008 23:28:29 Jim McCoy wrote: > >> After poking around a bit in the OTP sources it seems that it > would be > >> pretty trivial to add md4 to the crypto module. I will be testing a > >> few patches later this week, but before I throw together a real > EEP I > >> was hoping that this might be a simple-enough change that the > OTP team > >> might consider adding it without the need for the formal process. > > > > +1 for enhancement, also it would be useful to have DES in ECB > mode too > > (trivial). If someone interested, there is my implementation > based on erlang > > crypto driver (md4, des in ecb mode - used by mschapv2) > > http://pastie.org/283903 > > > > Also, why not make MD2 and finish dance with MD* crypto in erlang? :) > > > >> As for the rationale: some applications (dhts, etc) need a > large, fast > >> hash that has a good uniqueness distribution but are not worried > about > >> the security implications of selecting an algorithm that is > >> cryptographically weak. The md4 hash is about 50% faster than md5, > >> which is a real win when you are hashing thousands of items. Since > >> there are already "questionable" algorithms included in the crypto > >> module (e.g. md5 and rc2) it seems that a warning in the docs that > >> this algorithm should not be used for security-sensitive tasks would > >> be sufficient notice to developers. > >> > >> Any thoughts or objections? > >> > >> jim > >> _______________________________________________ > >> erlang-questions mailing list > >> erlang-questions > >> http://www.erlang.org/mailman/listinfo/erlang-questions > > > > _______________________________________________ > > erlang-questions mailing list > > erlang-questions > > http://www.erlang.org/mailman/listinfo/erlang-questions > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > > From cktgatb Mon Oct 6 17:34:21 2008 From: cktgatb (deepblue_other) Date: Mon, 6 Oct 2008 08:34:21 -0700 (PDT) Subject: [erlang-questions] re cursive fun() In-Reply-To: References: <19820386.post@talk.nabble.com> Message-ID: <19840331.post@talk.nabble.com> the example I gave was not suppose to be a practical one, I just wanted to ask how to recursively call a anonymous function... Richard O'Keefe wrote: > > On 5 Oct 2008, at 4:19 pm, deepblue_other wrote: >> I have this going on >> >> FunVar = >> fun() -> >> ... >> FunVar() >> end. >> > Shouldn't this go in a FAQ somewhere? > Maybe it belongs in the reference manual. > > The quick answer is that if you need a recursive > function, why not write a recursive function in the > usual way? > > There's something particularly nasty about this > example. One normally proves (or at any rate > argues with vigourously waving hands for) the > termination of a recursive function by showing > that some non-negative measure of its arguments > strictly decreases on each recursive call, but > this function has no arguments. I think we need > to see more of it. > > The long answer is that you can always do > > Rec = fun (Self, Args) -> > .... > Self(Self, Args') > end, > Foo = fun (Args) -> Rec(Rec, Args) end, > > It's possible, but you are working against the > grain of the language, and there is most likely > a better way to achieve your goals. > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > > -- View this message in context: http://www.nabble.com/recursive-fun%28%29-tp19820386p19840331.html Sent from the Erlang Questions mailing list archive at Nabble.com. From dgud Mon Oct 6 18:01:03 2008 From: dgud (Dan Gudmundsson) Date: Mon, 06 Oct 2008 18:01:03 +0200 Subject: [erlang-questions] Convert a Mnesia "set" table to an "ordered_set" In-Reply-To: <60ed8a460810060717i67d6231dxbe28918fc751845@mail.gmail.com> References: <60ed8a460810060717i67d6231dxbe28918fc751845@mail.gmail.com> Message-ID: <48EA363F.4010305@erix.ericsson.se> It's not possible to change the type on mnesia tables. /Dan Greg Burri wrote: > Hi, > I already ask this question but it was hided into a mail about something > else. > > Is there a way to convert a mnesia table which has the type "set" to a > "ordered_set" one ? > For the moment I use "mnesia:backup/1" then I recreate my table with the > "ordered_set" type and I call "mnesia:restore/2" to retrieve my data. > It's a bit ugly... it isn't ? > > > /Greg Burri > > > ------------------------------------------------------------------------ > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions From 0x6e6562 Mon Oct 6 19:38:36 2008 From: 0x6e6562 (Ben Hood) Date: Mon, 6 Oct 2008 18:38:36 +0100 Subject: [erlang-questions] Some mnesia oddity In-Reply-To: <48E9BF0F.7080303@erix.ericsson.se> References: <48B7DB67.7010608@erix.ericsson.se> <269388e30810050420w38e3cc77h23dea901c39d6cc1@mail.gmail.com> <48E9BF0F.7080303@erix.ericsson.se> Message-ID: <269388e30810061038u66e36bd9w7aeab7eaafa26449@mail.gmail.com> Dan, On Mon, Oct 6, 2008 at 8:32 AM, Dan Gudmundsson wrote: > You should be able to read the table in the same transaction, > but there is a bug in mnesia handling the special atom '_'. > > delete_object is not match delete do you have records with '_' in them?? Yes, but I may be missing the point. The test case I attached in my previous mail leads me to believe that wildcards do actually work with delete_object. As for the visibility of the deleted records, the same test case shows that deleted records are still visible to subsequent reads within the same transaction. Are you saying that this is the expected behavior? Or should I modify the test to iterate over the table with match_object and delete the records via their key? Thx, Ben From bryan.fink Mon Oct 6 20:26:28 2008 From: bryan.fink (Bryan Fink) Date: Mon, 6 Oct 2008 14:26:28 -0400 Subject: [erlang-questions] a little meta-programing help In-Reply-To: <8ca3fbe80810051631t2a1650f5x975f927c91e23415@mail.gmail.com> References: <8ca3fbe80810051515m6b983822re94985aa0b63248c@mail.gmail.com> <1c89b3a10810051612r6e341282v54d0f94262072dbb@mail.gmail.com> <8ca3fbe80810051631t2a1650f5x975f927c91e23415@mail.gmail.com> Message-ID: On Sun, Oct 5, 2008 at 7:31 PM, anders conbere wrote: > On Sun, Oct 5, 2008 at 4:12 PM, Antoine Koener wrote: >> On Mon, Oct 6, 2008 at 12:15 AM, anders conbere wrote: >>> Today I sat down to try to make working with mochiweb a little cleaner >>> for myself. I wanted a way to specify a list of mappings between url >>> patterns and methods to be called with the matched variables from >>> them. I quickly ran into issues with not being able to create patterns >>> dynamically, and then tried using funs to wrap that functionality but >>> pretty soon I was back at the same mess I started with. >>> >> >> I used the list_to_atom fun to build the module name. >> This is not recommended but it's still really useful: >> check out: http://easyerl.blogspot.com/2008/07/my-mochiweb-webservice.html > > Yeah, so I'm working more under the presumption that I can specify the > route to the module for each mapped url pattern. I'm not supper > interested in mapping urls to modules from the actual url text. Hi, Anders. I might suggest that you take a look at the webmachine project. It has a module that does dispatch and binding on URLs, and is built on top of mochiweb. I'm not sure if it's exactly what you're looking for, but it's in the same vein. Take a look at webmachine_dispatcher.erl from http://code.google.com/p/webmachine/ Details about its dispatch configuration syntax are here: http://code.google.com/p/webmachine/wiki/DispatchConfiguration -Bryan From oscar Mon Oct 6 20:35:19 2008 From: oscar (=?utf-8?Q?Oscar_Hellstr=C3=B6m?=) Date: Mon, 6 Oct 2008 19:35:19 +0100 (BST) Subject: [erlang-questions] tcp sockets - not clear In-Reply-To: <859063.6411223317795325.JavaMail.root@zimbra> Message-ID: <21022895.6431223318119607.JavaMail.root@zimbra> Hi, I'm assuming that a object is something running in a separate thread, which means that you will have to have a thread safe implementation of the send() function to be able to get the messages through without problems. AFAIK know at least the POSIX implementations are thread safe. Another important part here is that the whole message must be put on the wire before any part of any other message is, which actually means that the send() function need to support atomicy. If this is not the case for you send() function you probably need to serialise the sending. You can read more about this here: http://www.almaden.ibm.com/cs/people/marksmith/sendmsg.html Keep in mind that TCP packages can be fragmented on the way, and you need to assemble them yourself unless you use use the {packet, 1|2|4} option (and implement that on the flash side), i.e. you need some defined protocol. If you're using a text based protocol this is less of a problem (or more depending on who you are) I guess. >From the erlang side we seem to have the same issue that we need to serialise the data to be absolutely sure that messages are not intervened (since the inet_drv.c essentially calls send() at some point). Someone please correct me if I'm wrong here. Hope this helps. ----- Original Message ----- From: "deepblue_other" To: erlang-questions Sent: Sunday, 5 October, 2008 9:07:08 AM GMT -08:00 US/Canada Pacific Subject: [erlang-questions] tcp sockets - not clear hello everyone Im building a system with a Flash front-end and an Erlang back-end and have some confusion in a case where there is a single socket on the back-end per user (per single socket on the front-end). I want to have multiple independent objects on the front-end send messages to the back-end, but am not sure how the simultaneous transmission would be handled. This probably stems from my somewhat clowdly understanding of TCP. Say there are 3 objects that initiate a send() method on the front-end (almost at the same time) and send a semi large message each to the back-end. Each message would be ID'd by the front-end so that when received back it can be routed to the appropriate callback. Is this possible? since the packets are being assembled in the {tcp, Socket, Data} pattern match, peace by peace, would the correct peaces of the individual messages be stiched together? (doesnt seem like they would). if that wont work then I would just have the serialize the sending/receiving, which is not too horrible... thanks -- View this message in context: http://www.nabble.com/tcp-sockets---not-clear-tp19826070p19826070.html Sent from the Erlang Questions mailing list archive at Nabble.com. Best regards -- Oscar Hellstr?m, oscar Phone: +44 (0)798 45 44 773 Mobile: +44 (0)207 65 50 337 Web: http://www.erlang-consulting.com From aconbere Mon Oct 6 20:42:51 2008 From: aconbere (anders conbere) Date: Mon, 6 Oct 2008 11:42:51 -0700 Subject: [erlang-questions] a little meta-programing help In-Reply-To: References: <8ca3fbe80810051515m6b983822re94985aa0b63248c@mail.gmail.com> <1c89b3a10810051612r6e341282v54d0f94262072dbb@mail.gmail.com> <8ca3fbe80810051631t2a1650f5x975f927c91e23415@mail.gmail.com> Message-ID: <8ca3fbe80810061142y21217e50j60a9846ad15588e6@mail.gmail.com> On Mon, Oct 6, 2008 at 11:26 AM, Bryan Fink wrote: > On Sun, Oct 5, 2008 at 7:31 PM, anders conbere wrote: >> On Sun, Oct 5, 2008 at 4:12 PM, Antoine Koener wrote: >>> On Mon, Oct 6, 2008 at 12:15 AM, anders conbere wrote: >>>> Today I sat down to try to make working with mochiweb a little cleaner >>>> for myself. I wanted a way to specify a list of mappings between url >>>> patterns and methods to be called with the matched variables from >>>> them. I quickly ran into issues with not being able to create patterns >>>> dynamically, and then tried using funs to wrap that functionality but >>>> pretty soon I was back at the same mess I started with. >>>> >>> >>> I used the list_to_atom fun to build the module name. >>> This is not recommended but it's still really useful: >>> check out: http://easyerl.blogspot.com/2008/07/my-mochiweb-webservice.html >> >> Yeah, so I'm working more under the presumption that I can specify the >> route to the module for each mapped url pattern. I'm not supper >> interested in mapping urls to modules from the actual url text. > > Hi, Anders. I might suggest that you take a look at the webmachine > project. It has a module that does dispatch and binding on URLs, and > is built on top of mochiweb. I'm not sure if it's exactly what you're > looking for, but it's in the same vein. > > Take a look at webmachine_dispatcher.erl from > > http://code.google.com/p/webmachine/ > > Details about its dispatch configuration syntax are here: Interesting it looks like it does what I was considering which is writing matching code specifically for this. It seems like there are many good reasons to expose more of erlang's pattern matching tools to developers. I'm not sure historically what the reason behind not exposing the matching primitives is, but it would certainly make metaprogramming in erlang a ton easier. ~ Anders > > http://code.google.com/p/webmachine/wiki/DispatchConfiguration > > -Bryan > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From cktgatb Mon Oct 6 21:07:02 2008 From: cktgatb (deepblue_other) Date: Mon, 6 Oct 2008 12:07:02 -0700 (PDT) Subject: [erlang-questions] tcp sockets - not clear In-Reply-To: <21022895.6431223318119607.JavaMail.root@zimbra> References: <19826070.post@talk.nabble.com> <21022895.6431223318119607.JavaMail.root@zimbra> Message-ID: <19844239.post@talk.nabble.com> thanks for the reply Oscar Hellstr?m-2 wrote: > > Hi, > > I'm assuming that a object is something running in a separate thread, > which means that you will have to have a thread safe implementation of the > send() function to be able to get the messages through without problems. > AFAIK know at least the POSIX implementations are thread safe. Another > important part here is that the whole message must be put on the wire > before any part of any other message is, which actually means that the > send() function need to support atomicy. If this is not the case for you > send() function you probably need to serialise the sending. You can read > more about this here: > http://www.almaden.ibm.com/cs/people/marksmith/sendmsg.html > well the flash VM does not support threading yet, so all the object instances run in the same thread - thus thread safety is not an issue. you did nail it when saying that the whole message must be on the wire, which is my original concern, but Im guessing that you guys might not be able to answer this question since how Flash internally handles this is somewhat undocumented. However I have a feeling that this is not an issue, going back to the fact that Flash is single threaded. the question I guess is if a A is sent after B, TCP will ensure that A is assembled correctly even if some parts of it come in after B. So TCP guarantees that messages arrive in one peace (are assembled correctly) but does not guarantee that they come in the order they were sent? Oscar Hellstr?m-2 wrote: > > Keep in mind that TCP packages can be fragmented on the way, and you need > to assemble them yourself unless you use use the {packet, 1|2|4} option > (and implement that on the flash side), i.e. you need some defined > protocol. > you confused me here a bit. Im using {packet, 4} at the moment, but Im not clear what I would have to do if it were {packet,0}, and what I have to do on the Flash side. The packet assembling would not be handled automatically by the TCP drivers on both Erlang and Flash side? Oscar Hellstr?m-2 wrote: > > If you're using a text based protocol this is less of a problem (or more > depending on who you are) I guess. > > From the erlang side we seem to have the same issue that we need to > serialise the data to be absolutely sure that messages are not intervened > (since the inet_drv.c essentially calls send() at some point). Someone > please correct me if I'm wrong here. > > Hope this helps. > > ----- Original Message ----- > From: "deepblue_other" > To: erlang-questions > Sent: Sunday, 5 October, 2008 9:07:08 AM GMT -08:00 US/Canada Pacific > Subject: [erlang-questions] tcp sockets - not clear > > > hello everyone > Im building a system with a Flash front-end and an Erlang back-end and > have > some confusion in a case where there is a single socket on the back-end > per > user (per single socket on the front-end). > I want to have multiple independent objects on the front-end send messages > to the back-end, but am not sure how the simultaneous transmission would > be > handled. This probably stems from my somewhat clowdly understanding of > TCP. > Say there are 3 objects that initiate a send() method on the front-end > (almost at the same time) and send a semi large message each to the > back-end. Each message would be ID'd by the front-end so that when > received > back it can be routed to the appropriate callback. Is this possible? > since the packets are being assembled in the {tcp, Socket, Data} pattern > match, peace by peace, would the correct peaces of the individual messages > be stiched together? (doesnt seem like they would). > > if that wont work then I would just have the serialize the > sending/receiving, which is not too horrible... > > thanks > -- > View this message in context: > http://www.nabble.com/tcp-sockets---not-clear-tp19826070p19826070.html > Sent from the Erlang Questions mailing list archive at Nabble.com. > > Best regards > -- > Oscar Hellstr?m, oscar > Phone: +44 (0)798 45 44 773 > Mobile: +44 (0)207 65 50 337 > Web: http://www.erlang-consulting.com > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -- View this message in context: http://www.nabble.com/tcp-sockets---not-clear-tp19826070p19844239.html Sent from the Erlang Questions mailing list archive at Nabble.com. From kenneth.lundin Mon Oct 6 21:25:47 2008 From: kenneth.lundin (Kenneth Lundin) Date: Mon, 6 Oct 2008 21:25:47 +0200 Subject: [erlang-questions] extending the scanner and parser In-Reply-To: <95be1d3b0810041127o3d733f09l5182c0499ee57daa@mail.gmail.com> References: <95be1d3b0810030413p52bc5b58uf22c6790d64f9f35@mail.gmail.com> <20081003151527.GA28655@myrtle.kent.ac.uk> <95be1d3b0810031126t5fb7b8b9x48bb75c3895a330e@mail.gmail.com> <3dbc6d1c0810041115p571160fft458be1a867ff6cf2@mail.gmail.com> <95be1d3b0810041127o3d733f09l5182c0499ee57daa@mail.gmail.com> Message-ID: On Sat, Oct 4, 2008 at 8:27 PM, Vlad Dumitrescu wrote: > On Sat, Oct 4, 2008 at 20:15, Robert Virding wrote: >> Another solution which may help you is to use leex for generating the >> scanner. As I said we plan to integrate the required functionality in the official scanner and we can not have dependencies to components which are not part of the distribution in the scanner. We also already have the scanner so there is really no need to implement a new one with Leex. It might whowever be a good thing to have leex as part of the distribution but we can take that dicusssion separately. It gives you much more freedom in deciding what to return, so you >> could return both the value and/or the chars if you wish. However, I don't >> think it will give all the data you want, you can the line number, >> characters and length of each token. >> >> If you want to use yecc for generating the parser, which really does >> simplify matters, you have to a little circumspect because it only accepts >> tokens in the form {Type,Line} or {Type,Line,Value}. It does place any >> restrictions on the vaule. We already use yecc for the parser and it will be no problem to e.g. let the Line info in the tokens be an arbitrarily complex tuple instead. > > Thank you for the advice! I considered that, but I'd rather use the > standard lexer and parser, to be sure the results are exactly the same > as they should (except the presentation). Actually, now that I think > of it, I did try it, but got trouble with the more esoteric parts > (like multi-line strings) and abandoned that path. Maintenance would > still be a headache. > > best regards, > Vlad > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > /Kenneth Erlang/OTP team, Ericsson From michael.regen Mon Oct 6 21:41:46 2008 From: michael.regen (Michael Regen) Date: Mon, 6 Oct 2008 21:41:46 +0200 Subject: [erlang-questions] How to build Erlang with libcmt (/MT) under windows? In-Reply-To: <9b59d0270810051004u391f464k112d5175573a95f4@mail.gmail.com> References: <9b59d0270810051004u391f464k112d5175573a95f4@mail.gmail.com> Message-ID: <9b59d0270810061241g32995b3k5ce8da6221812912@mail.gmail.com> Hi, I think I found a solution. My very limited tests showed no problems so far. Question remains whether I should expect something bad to happen. Is it possible for someone with more insight into the code (shy glance to the Erlang emulator coders :) ) to give a rough estimation whether static binding of the C runtime library might lead to problems? I understand it is difficult by various aspects to publish the test suite used by Ericsson to test the Erlang distributions. And probably difficult to use. But here I ran into a situation where it would be quite usefull... My approach is attached to this mail. The small diffs simply make sure that the /MT switch is used by the compiler/linker. Probably they overshoot the mark. You need to run 'otp_build configure' after applying the patches. And my initial assumption about the error message below was wrong. _dosmaperr is a function which is contained in the static libcmt but not in msvcr??.dll. I have no clue why. However you do not want it when statically linking to libcmt. Regards, Michael On Sun, Oct 5, 2008 at 7:04 PM, Michael Regen wrote: > Hi, > > Does anyone a little bit more experienced with the Erlang build mechanism > know how to compile and link Erlang with libcmt instead of msvcrt? > The default mechanism builds Erlang with the /MD switch which means the C > standard libraries are accessed as threaded dll MSVCR??.DLL. This also means > you cannot simply copy Erlang to another computer as long as the correct C > runtime is not installed there. > > I am trying to figure out how to statically bind the libcmt library. > Normally you do this by using the /MT switch. > > So far I tried to change the erts\etc\win32\cygwin_tools\vc\cc.sh and ld.sh > scripts but with no good effects. I always get the usual error messages like > if you mix libraries compiled with different switches. > > In cc.sh setting > MD_FORCED=true > MD=-MT > and in ld.sh > STDLIB=LIBCMT.LIB > > just leads me to: > > LIBCMT.LIB(dosmap.obj) : error LNK2005: __dosmaperr already defined in > dosmap.o > Creating library > c:/dev/erlang/ErlangOTP/otp_src_R12B-4/bin/win32/erl_dll.lib and object > c:/dev/erlang/ErlangOTP/otp_src_R12B-4/bin/win32/erl_dll.exp > c:/dev/erlang/ErlangOTP/otp_src_R12B-4/bin/win32/beam.smp.dll : fatal error > LNK1169: one or more multiply defined symbols found > > Thank you! > > Regards, > Michael > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081006/4e918bdb/attachment.html -------------- next part -------------- A non-text attachment was scrubbed... Name: cc.sh.patch Type: application/octet-stream Size: 1217 bytes Desc: not available Url : http://www.erlang.org/pipermail/erlang-questions/attachments/20081006/4e918bdb/attachment.obj -------------- next part -------------- A non-text attachment was scrubbed... Name: ld.sh.patch Type: application/octet-stream Size: 374 bytes Desc: not available Url : http://www.erlang.org/pipermail/erlang-questions/attachments/20081006/4e918bdb/attachment-0001.obj -------------- next part -------------- A non-text attachment was scrubbed... Name: Makefile.in.patch Type: application/octet-stream Size: 308 bytes Desc: not available Url : http://www.erlang.org/pipermail/erlang-questions/attachments/20081006/4e918bdb/attachment-0002.obj -------------- next part -------------- A non-text attachment was scrubbed... Name: Makefile.patch Type: application/octet-stream Size: 314 bytes Desc: not available Url : http://www.erlang.org/pipermail/erlang-questions/attachments/20081006/4e918bdb/attachment-0003.obj From erlang-questions_efine Mon Oct 6 22:34:07 2008 From: erlang-questions_efine (Edwin Fine) Date: Mon, 6 Oct 2008 13:34:07 -0700 (PDT) Subject: [erlang-questions] tcp sockets - not clear In-Reply-To: <21022895.6431223318119607.JavaMail.root@zimbra> References: <19826070.post@talk.nabble.com> <21022895.6431223318119607.JavaMail.root@zimbra> Message-ID: <19845876.post@talk.nabble.com> Oscar Hellstr?m-2 wrote: > > I'm assuming that a object is something running in a separate thread, > which means that you will have to have a thread safe implementation of the > send() function to be able to get the messages through without problems. > AFAIK know at least the POSIX implementations are thread safe. Another > important part here is Huh, I didn't think of it in that way. I was assuming that each object (i.e. thread) would open its own socket, not share one socket amongst multiple threads. Sharing the channel would really complicate things, as you rightly say. You'd have to create a protocol to multiplex the data onto the channel, and demultiplex it on the other side, handling fragmentation properly. On the other hand, maybe it will be necessary to have a shared socket if there are many objects (threads) and it's not practical, or too inefficient, for each one to have its own socket. If I am misunderstanding any of this, please correct me. -- View this message in context: http://www.nabble.com/tcp-sockets---not-clear-tp19826070p19845876.html Sent from the Erlang Questions mailing list archive at Nabble.com. From mpharrison Mon Oct 6 23:17:01 2008 From: mpharrison (harry) Date: Mon, 6 Oct 2008 14:17:01 -0700 (PDT) Subject: [erlang-questions] ?DATE and ?TIME MACROs Message-ID: Hi, trawling through the archives I found the answer to how to do a ? FUNCTION macro. How would you do ?DATE and ?TIME (apart from erlc -DDATE=`time` .... or something similar, which is *nix specific) Would there be any mileage in adding these (and ?FUNCTION) to epp? Rgds, Matthew (aka Harry) From tony Tue Oct 7 01:34:07 2008 From: tony (Tony Arcieri) Date: Mon, 6 Oct 2008 17:34:07 -0600 Subject: [erlang-questions] Extracting capture group names from regular expressions Message-ID: I'm trying to write an API which accepts a regexp with arbitrary named capture groups as input. I'm using the re module, and have had success using named subgroups if the names are known ahead of time. However, I'd like to return a mapping of arbitrary named capture groups from the original regular expression to the matched values. Consider the following regular expression with named subpatterns: "(?\\w+) (?\\w+)" If this were applied to the string "baz qux" I'd like to return the following: [{"foo", "baz"}, {"bar", "qux"}] However, it looks as if I must provide the names of the capture groups I want returned in the capture tuple I pass to re:run. Is there any way to extract the names of the subgroups from a compiled regular expression? Or is there some option I can pass to re:run that I'm missing which will return a mapping of subgroup names to what they matched? -- Tony Arcieri medioh.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081006/9b691b62/attachment.html From yoursurrogategod Tue Oct 7 01:51:46 2008 From: yoursurrogategod (YourSurrogateGod) Date: Mon, 6 Oct 2008 16:51:46 -0700 (PDT) Subject: [erlang-questions] Erlang's security when compared to Ada Message-ID: This is an interesting article that I've found when it comes to security that a programming language can provide. http://www.net-security.org/secworld.php?id=6619 By no means I'm trying to compare Ada to Erlang. There are far too many things to take into account. However, I would like to know just how well Erlang measures up to the features that are part of the Ada language which make it so predictable and secure. I'd love to hear some input from fellow Erlang programmers who have a background in Ada. From ok Tue Oct 7 04:02:45 2008 From: ok (Richard O'Keefe) Date: Tue, 7 Oct 2008 15:02:45 +1300 Subject: [erlang-questions] re cursive fun() In-Reply-To: <19825467.post@talk.nabble.com> References: <19820386.post@talk.nabble.com> <6c2563b20810050213r7ea28fdbp9b2205332b3662a2@mail.gmail.com> <19825467.post@talk.nabble.com> Message-ID: On 6 Oct 2008, at 4:12 am, deepblue_other wrote: > no shell is not the reason, I need a function that will only be > called from > within another function and I dont want to "pollute" the "module > wide" space > with another function, so Im putting in a nested one... This seems an extraordinarily weak reason. Putting local functions into a namespace that is designed for local functions is hardly polluting it! Note that if the 'inner' function is needed in two clauses of the same function, it cannot be inside both, so it would have to be at top level anyway. Somehow, I find myself writing nested functions all the time in Haskell, but never wanting to in Erlang. Of course, many functional language compilers implement nested functions by moving them out to top level anyway... It's a fundamental property of Erlang scope rules that there is no letrec. From sgrady Tue Oct 7 03:06:55 2008 From: sgrady (Steven Grady) Date: Mon, 6 Oct 2008 18:06:55 -0700 Subject: [erlang-questions] re cursive fun() In-Reply-To: <6c2563b20810050213r7ea28fdbp9b2205332b3662a2@mail.gmail.com> References: <19820386.post@talk.nabble.com> <6c2563b20810050213r7ea28fdbp9b2205332b3662a2@mail.gmail.com> Message-ID: BTW, this question has apparently come up before (multiple times). The key google phrase is "Y combinator": http://bc.tech.coop/blog/070611.html Steven On Oct 5, 2008, at 2:13 AM, Edwin Fine wrote: > I'm assuming that you want to do this in the shell, otherwise it > would be easier just to write the function in the usual way, e.g. > > myfun() -> > blah, blah, > myfun(). > > To create a fun that calls itself, you must realize that you are > creating an unnamed function. When you write > > fun(X) -> X * 2 end. > > this is compiled to a Fun data type, e.g. #Fun. > > Since the function does not have a name, it cannot refer to itself. > > When you write FunVar = fun(X) -> X * 2 end, the function is bound > to the variable FunVar. Because the binding takes place *after* the > fun is created, the fun cannot refer to the variable FunVar within > its definition. > > So how is it done? You have to pass the variable to the function so > that it "knows" what to call: > > FunVar = > fun(MySelf) -> > ... > MySelf(). > > Then when you call it, you call FunVar(FunVar). Looks strange but it > works. > > Example: Writing a simple generate and fold function using only a > fun() variable. > > 9> GenFold = > fun(0, Acc, _) -> > Acc; > (X, Acc, Fun) -> > Fun(X - 1, [X|Acc], Fun) > end. > #Fun > 10> GenFold(10, [], GenFold). > [1,2,3,4,5,6,7,8,9,10] > 11> > > Or a for loop: > > 22> For = > fun(Max, Max, ExecFun, _) -> > ok; > (N, Max, ExecFun, Next) -> > ExecFun(N), > Next(N + 1, Max, ExecFun, Next) > end. > #Fun > 23> For(0,10,fun(I) -> io:format("~B ", [I]) end, For). > 0 1 2 3 4 5 6 7 8 9 ok > 24> > > Stuff like this is described in Joe Armstrong's Erlang book. > > Hope this helps. > > On Sat, Oct 4, 2008 at 11:19 PM, deepblue_other > wrote: > > hello > I have this going on > > FunVar = > fun() -> > ... > FunVar() > end. > > so the compiler is complaining that FunVar is unbound at the place > where its > being used inside fun(); this makes sense, however Im wondering how > to make > this into a recursive function since there's no name to reference the > function with. > > thanks > -- > View this message in context: http://www.nabble.com/recursive-fun%28%29-tp19820386p19820386.html > Sent from the Erlang Questions mailing list archive at Nabble.com. > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081006/898be408/attachment-0001.html From ok Tue Oct 7 04:43:19 2008 From: ok (Richard O'Keefe) Date: Tue, 7 Oct 2008 15:43:19 +1300 Subject: [erlang-questions] re cursive fun() In-Reply-To: <8e04b5820810050711s5d4ef554v50131c481fa19e85@mail.gmail.com> References: <19820386.post@talk.nabble.com> <48E8892E.5040204@it.uu.se> <8e04b5820810050711s5d4ef554v50131c481fa19e85@mail.gmail.com> Message-ID: <58B11B10-F2AA-4702-A625-A73F9F239A40@cs.otago.ac.nz> On 6 Oct 2008, at 3:11 am, Ciprian Dorin Craciun wrote: > About this subject, I would ask if isn't it better / easier / > clearer to add a special function name / keyword that would refer to > the function itself. This would also have a few advantages: Please write an EEP about this. > > * first it will solve the recursivity problem described above; The particular example here seems to be one that would have been better addressed using existing debugging tools. Recursiveness is not a problem; it's *anonymous* recursive functions. > > * (maybe) it could also improve efficiency (because you know > exactly what function you're calling, without any lookup); (this is > just an assumption, maybe inside the beam file the lookup does not > exist); (certainly it is more efficient than the proposed solution --- > sending the function as an argument;) The best recommendation that has been given is to use a plain ordinary top level function. This is _already_ more efficient than anything based on funs could be (because it is _certain_ not to need to unpack or repack outer variables), and it is certainly easier to get your head around (*some* variables in a function refer to outer variables, *some* do not, despite having the same name as outer variables). > > * it will assist in refactoring --- changing a recursive function > name will have no impact on it's code; Yes it will. Suppose we add something like Factorial = fun:Self (N) when N > 1 -> N*Self(N-1) ; (N) when N >= 0 -> 1 end, [Factorial(X) || X <- [3,1,4,1,5,9,2,6,5,3,5]] Changing "Self" in one place means it had better be changed in other places. For that matter, changing "Factorial" in one place means it has to be changed in other places. > > * it could clearly mark the fact that the function calls itself. It's hard to see how. The mere existence of a mark (such as :Self) is no guarantee that the body of the function *uses* it. And if you are thinking in terms of something like this_fun(), please, we've suffered enough from C already, and don't need any more like that. Consider F = fun:Outer (...) -> ... G = fun:Inner (...) -> ... Inner(X) ... ... Outer(Y) ... end ... Outer ... G ... end With a hook like this, the inner function can not only refer to itself, but also to the function that contains it. With a 'this_fun()' approach, it can't. > As for disadvantages I really do not see any. Try looking just a _little_ harder. > > P.S.: I think this solution could be equally applied to all > languages (mainly Lisp like). Most functional languages don't *need* it because they have 'letrec'. (In Lisp it's called 'labels'.) Even BCPL had letrec, let F(...) = E1 and G(...) = E2 and H(...) = E3 was a letrec in which F G and H could refer to each other. > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From zerthurd Tue Oct 7 06:02:54 2008 From: zerthurd (Maxim Treskin) Date: Tue, 7 Oct 2008 11:02:54 +0700 Subject: [erlang-questions] ?DATE and ?TIME MACROs In-Reply-To: References: Message-ID: Hello ?DATE and ?TIME are common and constant for whole application in compilation time. It is not similar to ?FUNCTION, ?MODULE, ?LINE which cannot be specified by -D parameter of erlc. So, better way to definition of ?DATE and ?TIME is commandline options of erlc, specified in Makefile. However it is good idea to add ?FUNCTION to epp. -- Maxim Treskin -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081007/3e1f9114/attachment.html From kenneth.lundin Tue Oct 7 07:57:27 2008 From: kenneth.lundin (Kenneth Lundin) Date: Tue, 7 Oct 2008 07:57:27 +0200 Subject: [erlang-questions] Erlang external binary term format In-Reply-To: References: <19830781.post@talk.nabble.com> <19830881.post@talk.nabble.com> Message-ID: Hi Christian, There is absolutely no reason to look at the file you are suggesting now when the contents of that file is moved into the official documentation (since R12B) and is available in both html and pdf. We will actually remove the file erl_ext_dist.txt since it is no longer needed. /Kenneth ERlang/OTP team at Ericsson On Mon, Oct 6, 2008 at 8:12 AM, Christian wrote: > You might want to look at > ./erts/emulator/internal_doc/erl_ext_dist.txt in the source tree. > > > On Mon, Oct 6, 2008 at 3:29 AM, deepblue_other wrote: >> >> for example >> one day I was looking at the term_to_binary() output of >> {binaries,"are",useful} >> and it was: >> 131,104,3,100,0,8,98,105,110,97,114,105,101,115,107,0,3,97,114,101,100,0,6,117,115,101,102,117,108 > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From dgud Tue Oct 7 08:30:44 2008 From: dgud (Dan Gudmundsson) Date: Tue, 07 Oct 2008 08:30:44 +0200 Subject: [erlang-questions] Some mnesia oddity In-Reply-To: <269388e30810061038u66e36bd9w7aeab7eaafa26449@mail.gmail.com> References: <48B7DB67.7010608@erix.ericsson.se> <269388e30810050420w38e3cc77h23dea901c39d6cc1@mail.gmail.com> <48E9BF0F.7080303@erix.ericsson.se> <269388e30810061038u66e36bd9w7aeab7eaafa26449@mail.gmail.com> Message-ID: <48EB0214.5090701@erix.ericsson.se> Ben Hood wrote: > Dan, > > On Mon, Oct 6, 2008 at 8:32 AM, Dan Gudmundsson wrote: >> You should be able to read the table in the same transaction, >> but there is a bug in mnesia handling the special atom '_'. >> >> delete_object is not match delete do you have records with '_' in them?? > Yes, but I may be missing the point. The test case I attached in my > previous mail leads me to believe that wildcards do actually work with > delete_object. No it doesn't, see the first mail in this thread, if it does in some cases it is a bug too, is shouldn't work. > As for the visibility of the deleted records, the same test case shows > that deleted records are still visible to subsequent reads within the > same transaction. Are you saying that this is the expected behavior? That's a part of the bug above, you shouldn't see the deleted records, but then since you are not suppose to be able to delete them with the wildcard '_'. > Or should I modify the test to iterate over the table with > match_object and delete the records via their key? Yes, or clear_table (but that's not allowed inside a transaction). I will probably disallow '_' and '$[1-n]' in mnesia:delete_object. Regards /Dan > Thx, > Ben > From 0x6e6562 Tue Oct 7 09:58:16 2008 From: 0x6e6562 (Ben Hood) Date: Tue, 7 Oct 2008 08:58:16 +0100 Subject: [erlang-questions] Some mnesia oddity In-Reply-To: <48EB0214.5090701@erix.ericsson.se> References: <48B7DB67.7010608@erix.ericsson.se> <269388e30810050420w38e3cc77h23dea901c39d6cc1@mail.gmail.com> <48E9BF0F.7080303@erix.ericsson.se> <269388e30810061038u66e36bd9w7aeab7eaafa26449@mail.gmail.com> <48EB0214.5090701@erix.ericsson.se> Message-ID: <269388e30810070058m43b79b33sda220791309291ab@mail.gmail.com> Dan, On Tue, Oct 7, 2008 at 7:30 AM, Dan Gudmundsson wrote: > No it doesn't, see the first mail in this thread, if it does in some cases > it is a bug too, is shouldn't work. Good to know that this is not the intended behavior, even if it does seem to work in a variety of cases. This clears up the mystery of what this is not documented in the mnesia guide. > That's a part of the bug above, you shouldn't see the deleted records, > but then since you are not suppose to be able to delete them with the > wildcard > '_'. I converted the test to iterate over the table with mnesia:match_object/1 and then remove each element mnesia:delete/1 and then the results of this were visible within the same transaction. So this is consistent with the fact that you are not supposed to be able to use wildcards with delete_object. > I will probably disallow '_' and '$[1-n]' in mnesia:delete_object. Thanks for the heads up. I will remove all usages of wildcards in mnesia:delete_object/1 calls in our code. Thx, Ben From mats.cronqvist Tue Oct 7 10:28:19 2008 From: mats.cronqvist (Mats Cronqvist) Date: Tue, 07 Oct 2008 10:28:19 +0200 Subject: [erlang-questions] Get a range of tuples from a Mnesia table In-Reply-To: <6c2563b20810041111t401ebb0fh5482d383438f0b8b@mail.gmail.com> References: <60ed8a460810040919qcf9dd37m994bbf6932f18cc0@mail.gmail.com> <6c2563b20810041111t401ebb0fh5482d383438f0b8b@mail.gmail.com> Message-ID: <48EB1DA3.8030304@gmail.com> Edwin Fine wrote: > Looking through the docs, I see that if you are using an mnesia table > that is ram_copies or disc_copies, you can do certain fast operations > on the associated ets table. One such operation (which is recommended > only for debugging, but what the heck) is ets:slot(Tab, I), which > returns the I'th record in the table. slot/2 does not in general return the I:th record. it does return a one-element list of the I:th record, iff the table is of type ordered_set. for other table types, it returns a list of all records in the I:th slot, i.e. all objects whose keys hash to the same value. mats From mats.cronqvist Tue Oct 7 11:35:09 2008 From: mats.cronqvist (Mats Cronqvist) Date: Tue, 07 Oct 2008 11:35:09 +0200 Subject: [erlang-questions] ?DATE and ?TIME MACROs In-Reply-To: References: Message-ID: <48EB2D4D.2060909@gmail.com> harry wrote: > Hi, > > trawling through the archives I found the answer to how to do a ? > FUNCTION macro. > > How would you do ?DATE and ?TIME (apart from erlc -DDATE=`time` .... > or something similar, which is *nix specific) > > -define(DATE,proplists:get_value(time,?MODULE:module_info(compile))). From zerthurd Tue Oct 7 12:22:28 2008 From: zerthurd (Maxim Treskin) Date: Tue, 7 Oct 2008 17:22:28 +0700 Subject: [erlang-questions] ?DATE and ?TIME MACROs In-Reply-To: <48EB2D4D.2060909@gmail.com> References: <48EB2D4D.2060909@gmail.com> Message-ID: On 07/10/2008, Mats Cronqvist wrote: > > -define(DATE,proplists:get_value(time,?MODULE:module_info(compile))). Fine! :D -- Maxim Treskin From mpharrison Tue Oct 7 12:22:35 2008 From: mpharrison (harry) Date: Tue, 7 Oct 2008 03:22:35 -0700 (PDT) Subject: [erlang-questions] ?DATE and ?TIME MACROs In-Reply-To: <48EB2D4D.2060909@gmail.com> References: <48EB2D4D.2060909@gmail.com> Message-ID: <18e4500f-28db-4efd-b399-885fc7ff3e68@l62g2000hse.googlegroups.com> Excellent, thanks! I'm struggling to find docs on module_info. I'm guessing erlc inserts it into each module, and it uses beam_lib? Rgds, Matthew (aka Harry) On Oct 7, 10:35?am, Mats Cronqvist wrote: > harry wrote: > > Hi, > > > trawling through the archives I found the answer to how to do a ? > > FUNCTION macro. > > > How would you do ?DATE and ?TIME (apart from erlc -DDATE=`time` .... > > or something similar, which is *nix specific) > > -define(DATE,proplists:get_value(time,?MODULE:module_info(compile))). > > _______________________________________________ > erlang-questions mailing list > erlang-questi...://www.erlang.org/mailman/listinfo/erlang-questions From 0x6e6562 Tue Oct 7 13:19:05 2008 From: 0x6e6562 (Ben Hood) Date: Tue, 7 Oct 2008 12:19:05 +0100 Subject: [erlang-questions] Some mnesia oddity In-Reply-To: <269388e30810070058m43b79b33sda220791309291ab@mail.gmail.com> References: <48B7DB67.7010608@erix.ericsson.se> <269388e30810050420w38e3cc77h23dea901c39d6cc1@mail.gmail.com> <48E9BF0F.7080303@erix.ericsson.se> <269388e30810061038u66e36bd9w7aeab7eaafa26449@mail.gmail.com> <48EB0214.5090701@erix.ericsson.se> <269388e30810070058m43b79b33sda220791309291ab@mail.gmail.com> Message-ID: <269388e30810070419n1229dc14sce7fd2e51d65391d@mail.gmail.com> Dan, On Tue, Oct 7, 2008 at 8:58 AM, Ben Hood <0x6e6562> wrote: >> I will probably disallow '_' and '$[1-n]' in mnesia:delete_object. > > Thanks for the heads up. I will remove all usages of wildcards in > mnesia:delete_object/1 calls in our code. Just FYI: When I changed the wildcard deletes with exact key matches in a loop, the performance of removing entries in this table dropped by about 40% in my particular application. Is there some way to remove batches of records more efficiently? Would it make a difference to use a dirty_delete? Thx, Ben From vychodil.hynek Tue Oct 7 13:32:37 2008 From: vychodil.hynek (Hynek Vychodil) Date: Tue, 7 Oct 2008 13:32:37 +0200 Subject: [erlang-questions] re cursive fun() In-Reply-To: <58B11B10-F2AA-4702-A625-A73F9F239A40@cs.otago.ac.nz> References: <19820386.post@talk.nabble.com> <48E8892E.5040204@it.uu.se> <8e04b5820810050711s5d4ef554v50131c481fa19e85@mail.gmail.com> <58B11B10-F2AA-4702-A625-A73F9F239A40@cs.otago.ac.nz> Message-ID: <20081007113238.7D4902407D@relay.gooddata.com> On Tue, Oct 7, 2008 at 4:43 AM, Richard O'Keefe wrote: > > On 6 Oct 2008, at 3:11 am, Ciprian Dorin Craciun wrote: > > About this subject, I would ask if isn't it better / easier / > > clearer to add a special function name / keyword that would refer to > > the function itself. This would also have a few advantages: > > Please write an EEP about this. > > > > > * first it will solve the recursivity problem described above; > > The particular example here seems to be one that would have been > better addressed using existing debugging tools. > > Recursiveness is not a problem; it's *anonymous* recursive > functions. > > > > * (maybe) it could also improve efficiency (because you know > > exactly what function you're calling, without any lookup); (this is > > just an assumption, maybe inside the beam file the lookup does not > > exist); (certainly it is more efficient than the proposed solution --- > > sending the function as an argument;) > > The best recommendation that has been given is to use a plain > ordinary top level function. This is _already_ more efficient > than anything based on funs could be (because it is _certain_ > not to need to unpack or repack outer variables), and it is > certainly easier to get your head around (*some* variables > in a function refer to outer variables, *some* do not, > despite having the same name as outer variables). > > > > > * it will assist in refactoring --- changing a recursive function > > name will have no impact on it's code; > > Yes it will. Suppose we add something like > > Factorial = fun:Self (N) when N > 1 -> N*Self(N-1) > ; (N) when N >= 0 -> 1 > end, > [Factorial(X) || X <- [3,1,4,1,5,9,2,6,5,3,5]] > > Changing "Self" in one place means it had better be changed > in other places. For that matter, changing "Factorial" in > one place means it has to be changed in other places. > > > > > * it could clearly mark the fact that the function calls itself. > > It's hard to see how. The mere existence of a mark (such as :Self) > is no guarantee that the body of the function *uses* it. And if > you are thinking in terms of something like this_fun(), please, > we've suffered enough from C already, and don't need any more like > that. Consider > > F = fun:Outer (...) -> > ... G = fun:Inner (...) -> > ... Inner(X) ... > ... Outer(Y) ... > end > ... Outer ... G ... > end > Is there any problem write this think this way? F = begin Outher = fun(OSelf, ...) -> ... Inner = fun(ISelf, ....) -> ... ISelf(ISelf, X) ... ... OSelf(OSelf, Y) ... end, ... OSelf(OSelf, ...) ... Inner(Inner, ...) ... fun(Args) -> Outher(Outher, Args) end end. For Example factorial: Fact = begin F = fun(_, 0) -> 1; (Self, N) -> Self(Self, N-1)*N end, fun(N) -> F(F, N) end end. Some nontrivial example: 4> UpToGen = begin Outher = fun(_OSelf, M, M) -> []; (OSelf, Step, M) -> Inner = fun(_ISelf, N) when N>M -> []; (ISelf, N) -> [N | ISelf(ISelf, N+Step) ] end, [Inner(Inner, 0) | OSelf(OSelf, Step+1, M)] end, fun(Max) -> Outher(Outher, 1, Max) end end. #Fun 5> UpToGen(10). [[0,1,2,3,4,5,6,7,8,9,10], [0,2,4,6,8,10], [0,3,6,9], [0,4,8], [0,5,10], [0,6], [0,7], [0,8], [0,9]] > > With a hook like this, the inner function can not only refer to > itself, but also to the function that contains it. With a > 'this_fun()' approach, it can't. > > > As for disadvantages I really do not see any. > > Try looking just a _little_ harder. > > > > > P.S.: I think this solution could be equally applied to all > > languages (mainly Lisp like). > > Most functional languages don't *need* it because they > have 'letrec'. (In Lisp it's called 'labels'.) > Even BCPL had letrec, > let F(...) = E1 > and G(...) = E2 > and H(...) = E3 > was a letrec in which F G and H could refer to each other. > > > > > > _______________________________________________ > > erlang-questions mailing list > > erlang-questions > > http://www.erlang.org/mailman/listinfo/erlang-questions > > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -- --Hynek (Pichi) Vychodil -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081007/a9fabcbf/attachment.html From dgud Tue Oct 7 13:45:47 2008 From: dgud (Dan Gudmundsson) Date: Tue, 07 Oct 2008 13:45:47 +0200 Subject: [erlang-questions] Some mnesia oddity In-Reply-To: <269388e30810070419n1229dc14sce7fd2e51d65391d@mail.gmail.com> References: <48B7DB67.7010608@erix.ericsson.se> <269388e30810050420w38e3cc77h23dea901c39d6cc1@mail.gmail.com> <48E9BF0F.7080303@erix.ericsson.se> <269388e30810061038u66e36bd9w7aeab7eaafa26449@mail.gmail.com> <48EB0214.5090701@erix.ericsson.se> <269388e30810070058m43b79b33sda220791309291ab@mail.gmail.com> <269388e30810070419n1229dc14sce7fd2e51d65391d@mail.gmail.com> Message-ID: <48EB4BEB.6040607@erix.ericsson.se> Ben Hood wrote: > Dan, > > On Tue, Oct 7, 2008 at 8:58 AM, Ben Hood <0x6e6562> wrote: >>> I will probably disallow '_' and '$[1-n]' in mnesia:delete_object. >> Thanks for the heads up. I will remove all usages of wildcards in >> mnesia:delete_object/1 calls in our code. > > Just FYI: When I changed the wildcard deletes with exact key matches > in a loop, the performance of removing entries in this table dropped > by about 40% in my particular application. > > Is there some way to remove batches of records more efficiently? Would > it make a difference to use a dirty_delete? No not today, and I _guess_ that if I implement a match_delete like function it would cost about the same. The cost is in copying the operations to the temporary transaction store and searching it when doing the following operations, I can of course do something special but then that have to be checked (a performance cost) in every write and read operation. /Dan > Thx, > > Ben > From rasmussen.bryan Tue Oct 7 13:53:13 2008 From: rasmussen.bryan (bryan rasmussen) Date: Tue, 7 Oct 2008 13:53:13 +0200 Subject: [erlang-questions] xmerl_xpath and namespaces In-Reply-To: <48e6915d.050cc00a.5255.ffffba16@mx.google.com> References: <48e6915d.050cc00a.5255.ffffba16@mx.google.com> Message-ID: <3bb44c6e0810070453s64aba01dhbb57ffbc4714f065@mail.gmail.com> Hi Denis, 2008/10/3 denis : > Hello, > > > > I'm having some problem using xmerl_xpath on a document having namespaces. > I'm not sure I fully understand how all of this work and the problem should > not come from xmerl_xpath, but from my misunderstanding of xml, namespace, > xpath? > > It seems that with xpath, it's mandatory to give the namespace. > > > For instance, in a document like this: > > > > > > > targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/"> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > If I want to get all "element" attributes, I need to do a query like > > xmerl_xpath:string("//xs:simpleType", X) > > Is there a way to not having to give the namespace in the query ?? This XPath should get it //*[local-name()='simpleType'] but that would also get any element where the local name (xpath term for dom basename) of an element was simpleType so if your instance was this blah blah blah 3 blahs long! then the xpath would return both blah:simpleType and xs:simpleType, but how often is that a real problem. Cheers, Bryan Rasmussen From rasmussen.bryan Tue Oct 7 13:54:37 2008 From: rasmussen.bryan (bryan rasmussen) Date: Tue, 7 Oct 2008 13:54:37 +0200 Subject: [erlang-questions] Erlang with MonetDb Message-ID: <3bb44c6e0810070454s5cd3a829p524ce628808a2323@mail.gmail.com> Hi, Anyone out there made some erlang examples working with MonetDB? using ODBC acceptable. Cheers, Bryan Rasmussen From ulf.wiger Tue Oct 7 15:30:22 2008 From: ulf.wiger (Ulf Wiger (TN/EAB)) Date: Tue, 07 Oct 2008 15:30:22 +0200 Subject: [erlang-questions] Some mnesia oddity In-Reply-To: <269388e30810070419n1229dc14sce7fd2e51d65391d@mail.gmail.com> References: <48B7DB67.7010608@erix.ericsson.se> <269388e30810050420w38e3cc77h23dea901c39d6cc1@mail.gmail.com> <48E9BF0F.7080303@erix.ericsson.se> <269388e30810061038u66e36bd9w7aeab7eaafa26449@mail.gmail.com> <48EB0214.5090701@erix.ericsson.se> <269388e30810070058m43b79b33sda220791309291ab@mail.gmail.com> <269388e30810070419n1229dc14sce7fd2e51d65391d@mail.gmail.com> Message-ID: <48EB646E.3080104@ericsson.com> Ben Hood skrev: > > Is there some way to remove batches of records more efficiently? > Would it make a difference to use a dirty_delete? On replicated tables, using dirty writes or deletes for batch updates can easily be _less_ efficient (and considerably less safe) than using transactions. The reason is that, if you take a table lock, the overhead for starting the transaction, acquiring the lock and committing (where all operations are included in the commit message), becomes insignificant at some point, compared to the combined overhead of making an rpc call for each single operation. If you _know_ that the table isn't replicated, there are various dirty ways to speed things up, including perhaps even changing the table copy type to ram, making all changes directly on the ets table, and then changing the copy type back to disc_copies (if that's what it was from the beginning). Of course, if confronted, I'll deny that I ever wrote this. ;-) BR, Ulf W From mats.cronqvist Tue Oct 7 15:31:16 2008 From: mats.cronqvist (Mats Cronqvist) Date: Tue, 07 Oct 2008 15:31:16 +0200 Subject: [erlang-questions] ?DATE and ?TIME MACROs In-Reply-To: <18e4500f-28db-4efd-b399-885fc7ff3e68@l62g2000hse.googlegroups.com> References: <48EB2D4D.2060909@gmail.com> <18e4500f-28db-4efd-b399-885fc7ff3e68@l62g2000hse.googlegroups.com> Message-ID: <48EB64A4.90805@gmail.com> harry wrote: > Excellent, thanks! > > I'm struggling to find docs on module_info. > I'm guessing erlc inserts it into each module yes. > and it uses beam_lib? > afaik, no. it's just a regular exported function that would look something like this in Erlang. module_info() -> . module_info(Tag) -> try proplists:get_value(Tag,module_info()) catch _:_ -> exit(badarg) end. where is a constant term. this is just speculation on my part though. mats From dloutrein.lists Tue Oct 7 15:42:58 2008 From: dloutrein.lists (denis) Date: Tue, 7 Oct 2008 09:42:58 -0400 Subject: [erlang-questions] xmerl_xpath and namespaces In-Reply-To: <3bb44c6e0810070453s64aba01dhbb57ffbc4714f065@mail.gmail.com> References: <48e6915d.050cc00a.5255.ffffba16@mx.google.com> <3bb44c6e0810070453s64aba01dhbb57ffbc4714f065@mail.gmail.com> Message-ID: <48eb6764.070fc00a.3f1c.ffff96ce@mx.google.com> Hi bryan, > > > > If I want to get all "element" attributes, I need to do a query like > > > > xmerl_xpath:string("//xs:simpleType", X) > > > > Is there a way to not having to give the namespace in the query ?? > > This XPath should get it //*[local-name()='simpleType'] > I had test this before but where unable to get it working with R12B3. I tried it again yesterday with R12B4 and it works now. It was a bug which has been fixed. Cool ! Thanks for your answer Denis From richardc Tue Oct 7 16:19:04 2008 From: richardc (Richard Carlsson) Date: Tue, 07 Oct 2008 16:19:04 +0200 Subject: [erlang-questions] ?DATE and ?TIME MACROs In-Reply-To: <48EB64A4.90805@gmail.com> References: <48EB2D4D.2060909@gmail.com> <18e4500f-28db-4efd-b399-885fc7ff3e68@l62g2000hse.googlegroups.com> <48EB64A4.90805@gmail.com> Message-ID: <48EB6FD8.1000107@it.uu.se> Mats Cronqvist wrote: > afaik, no. it's just a regular exported function that would look > something like this in Erlang. > > module_info() -> . > module_info(Tag) -> > try proplists:get_value(Tag,module_info()) > catch _:_ -> exit(badarg) > end. > > where is a constant term. > this is just speculation on my part though. That used to be true, but these days they are simply wrappers around a couple of built-in (undocumented?) functions, like this: module_info() -> erlang:get_module_info(?MODULE). module_info(Tag) -> erlang:get_module_info(?MODULE, Tag). (Since the metadata is already loaded from a chunk in the beam file, there is no need to duplicate it in the code.) But the compiler inserts the functions, yes. /Richard From dmercer Tue Oct 7 16:29:18 2008 From: dmercer (David Mercer) Date: Tue, 7 Oct 2008 09:29:18 -0500 Subject: [erlang-questions] re cursive fun() In-Reply-To: <20081007113238.7D4902407D@relay.gooddata.com> References: <19820386.post@talk.nabble.com> <48E8892E.5040204@it.uu.se><8e04b5820810050711s5d4ef554v50131c481fa19e85@mail.gmail.com><58B11B10-F2AA-4702-A625-A73F9F239A40@cs.otago.ac.nz> <20081007113238.7D4902407D@relay.gooddata.com> Message-ID: <0F3BFEC2F16D4D66A6AF13B05F481CF3@SSI.CORP> On Tuesday, October 07, 2008, Hynek Vychodil wrote: > Is there any problem write this think this way? . . . > For Example factorial: > > Fact = begin F = fun(_, 0) -> 1; (Self, N) -> Self(Self, N-1)*N end, fun(N) -> F(F, N) end end. My only objection is that it pollutes the shell variable space with the extra function F. How about: Fact = fun(N) -> F = fun(_, 0) -> 1; (Self, N) -> Self(Self, N-1)*N end, F(F, N) end. Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081007/a5034993/attachment.html From mpharrison Tue Oct 7 16:32:16 2008 From: mpharrison (harry) Date: Tue, 7 Oct 2008 07:32:16 -0700 (PDT) Subject: [erlang-questions] ?DATE and ?TIME MACROs In-Reply-To: <48EB64A4.90805@gmail.com> References: <48EB2D4D.2060909@gmail.com> <18e4500f-28db-4efd-b399-885fc7ff3e68@l62g2000hse.googlegroups.com> <48EB64A4.90805@gmail.com> Message-ID: Cheers, I had a dig around in the source in compile, and found some other possible tags. But, I wonder, if this is not documented, might it change in the future? On Oct 7, 2:31?pm, Mats Cronqvist wrote: > harry wrote: > > Excellent, thanks! > > > I'm struggling to find docs on module_info. > > I'm guessing erlc inserts it into each module > > yes. > > > and it uses beam_lib? > > ?afaik, no. it's just a regular exported function that would look > something like this in Erlang. > > module_info() -> . > module_info(Tag) -> > ?try proplists:get_value(Tag,module_info()) > ?catch _:_ -> exit(badarg) > ?end. > > ?where is a constant term. > ?this is just speculation on my part though. > > ? mats > _______________________________________________ > erlang-questions mailing list > erlang-questi...://www.erlang.org/mailman/listinfo/erlang-questions From mpharrison Tue Oct 7 17:09:11 2008 From: mpharrison (harry) Date: Tue, 7 Oct 2008 08:09:11 -0700 (PDT) Subject: [erlang-questions] ?DATE and ?TIME MACROs In-Reply-To: <48EB6FD8.1000107@it.uu.se> References: <48EB2D4D.2060909@gmail.com> <18e4500f-28db-4efd-b399-885fc7ff3e68@l62g2000hse.googlegroups.com> <48EB64A4.90805@gmail.com> <48EB6FD8.1000107@it.uu.se> Message-ID: <42529f32-ebd1-418a-a582-d35459f92a5e@k37g2000hsf.googlegroups.com> Should I post on erlang-bugs to get module_info() and get_module_info() documented? They seem really useful. (I tried it & the info survives beam_lib:strip()) Rgds, Matthew. On Oct 7, 3:19?pm, Richard Carlsson wrote: > That used to be true, but these days they are simply > wrappers around a couple of built-in (undocumented?) > functions, like this: > > module_info() -> erlang:get_module_info(?MODULE). > module_info(Tag) -> erlang:get_module_info(?MODULE, Tag). > > (Since the metadata is already loaded from a chunk in the > beam file, there is no need to duplicate it in the code.) > > But the compiler inserts the functions, yes. > > ? ? /Richard > _______________________________________________ > erlang-questions mailing list > erlang-questi...://www.erlang.org/mailman/listinfo/erlang-questions From vychodil.hynek Tue Oct 7 17:47:08 2008 From: vychodil.hynek (Hynek Vychodil) Date: Tue, 7 Oct 2008 17:47:08 +0200 Subject: [erlang-questions] re cursive fun() In-Reply-To: <0F3BFEC2F16D4D66A6AF13B05F481CF3@SSI.CORP> References: <19820386.post@talk.nabble.com> <48E8892E.5040204@it.uu.se> <8e04b5820810050711s5d4ef554v50131c481fa19e85@mail.gmail.com> <58B11B10-F2AA-4702-A625-A73F9F239A40@cs.otago.ac.nz> <20081007113238.7D4902407D@relay.gooddata.com> <0F3BFEC2F16D4D66A6AF13B05F481CF3@SSI.CORP> Message-ID: <20081007154709.5F69224089@relay.gooddata.com> Yes of course, it can be done. There is little difference when closure is made. this second example can be rewritten (and simplified) in same manner: UpToGen = fun(Max) -> Outer = fun(_OSelf, Max) -> []; (OSelf, Step) -> Inner = fun(_ISelf, N) when N>Max -> []; (ISelf, N) -> [N | ISelf(ISelf, N+Step) ] end, [Inner(Inner, 0) | OSelf(OSelf, Step+1)] end, Outer(Outer, 1) end. On Tue, Oct 7, 2008 at 4:29 PM, David Mercer wrote: > On Tuesday, October 07, 2008, Hynek Vychodil wrote: > > > > > Is there any problem write this think this way? > > . . . > > > For Example factorial: > > > > > > Fact = begin F = fun(_, 0) -> 1; (Self, N) -> Self(Self, N-1)*N end, > fun(N) -> F(F, N) end end. > > > > My only objection is that it pollutes the shell variable space with the > extra function F. How about: > > > > Fact = fun(N) -> F = fun(_, 0) -> 1; (Self, N) -> Self(Self, N-1)*N end, > F(F, N) end. > > > > Cheers, > > > > David > -- --Hynek (Pichi) Vychodil -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081007/667cb54e/attachment-0001.html From erlang-questions_efine Tue Oct 7 17:54:40 2008 From: erlang-questions_efine (Edwin Fine) Date: Tue, 7 Oct 2008 11:54:40 -0400 Subject: [erlang-questions] Get a range of tuples from a Mnesia table In-Reply-To: <48EB1DA3.8030304@gmail.com> References: <60ed8a460810040919qcf9dd37m994bbf6932f18cc0@mail.gmail.com> <6c2563b20810041111t401ebb0fh5482d383438f0b8b@mail.gmail.com> <48EB1DA3.8030304@gmail.com> Message-ID: <6c2563b20810070854u3eb94b79u5c8d90c7b7a4373c@mail.gmail.com> RIght. He did say he was using an ordered_set, and I was imprecise in saying that it returned the record rather than a one-element list containing the record. Poetic license :) On Tue, Oct 7, 2008 at 4:28 AM, Mats Cronqvist wrote: > Edwin Fine wrote: > >> Looking through the docs, I see that if you are using an mnesia table that >> is ram_copies or disc_copies, you can do certain fast operations on the >> associated ets table. One such operation (which is recommended only for >> debugging, but what the heck) is ets:slot(Tab, I), which returns the I'th >> record in the table. >> > > slot/2 does not in general return the I:th record. > it does return a one-element list of the I:th record, iff the table is of > type ordered_set. for other table types, it returns a list of all records in > the I:th slot, i.e. all objects whose keys hash to the same value. > > mats > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081007/ce75a175/attachment.html From bob Tue Oct 7 18:34:28 2008 From: bob (Bob Ippolito) Date: Tue, 7 Oct 2008 09:34:28 -0700 Subject: [erlang-questions] Erlang with MonetDb In-Reply-To: <3bb44c6e0810070454s5cd3a829p524ce628808a2323@mail.gmail.com> References: <3bb44c6e0810070454s5cd3a829p524ce628808a2323@mail.gmail.com> Message-ID: <6a36e7290810070934k1a3fbf43k258c6220b6a56e75@mail.gmail.com> I don't have an answer for you, but we tried using MonetDB early this year and it was an epic failure, the database corrupted itself and at times the server would grow until it ran out of RAM. We unfortunately had to resort to a commercial column store because we couldn't get MonetDB to run for more than a few hours without crashing :( On Tue, Oct 7, 2008 at 4:54 AM, bryan rasmussen wrote: > Hi, > > Anyone out there made some erlang examples working with MonetDB? using > ODBC acceptable. > > > Cheers, > Bryan Rasmussen > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From oscar Tue Oct 7 18:42:17 2008 From: oscar (=?utf-8?Q?Oscar_Hellstr=C3=B6m?=) Date: Tue, 7 Oct 2008 17:42:17 +0100 (BST) Subject: [erlang-questions] tcp sockets - not clear In-Reply-To: <17015960.6921223397512269.JavaMail.root@zimbra> Message-ID: <15350725.6941223397737052.JavaMail.root@zimbra> Hi, See my comments embedded. ----- Original Message ----- From: "deepblue_other" To: erlang-questions Sent: Monday, 6 October, 2008 12:07:02 PM GMT -08:00 US/Canada Pacific Subject: Re: [erlang-questions] tcp sockets - not clear thanks for the reply Oscar Hellstr?m-2 wrote: > > Hi, > > I'm assuming that a object is something running in a separate thread, > which means that you will have to have a thread safe implementation of the > send() function to be able to get the messages through without problems. > AFAIK know at least the POSIX implementations are thread safe. Another > important part here is that the whole message must be put on the wire > before any part of any other message is, which actually means that the > send() function need to support atomicy. If this is not the case for you > send() function you probably need to serialise the sending. You can read > more about this here: > http://www.almaden.ibm.com/cs/people/marksmith/sendmsg.html > well the flash VM does not support threading yet, so all the object instances run in the same thread - thus thread safety is not an issue. you did nail it when saying that the whole message must be on the wire, which is my original concern, but Im guessing that you guys might not be able to answer this question since how Flash internally handles this is somewhat undocumented. However I have a feeling that this is not an issue, going back to the fact that Flash is single threaded. the question I guess is if a A is sent after B, TCP will ensure that A is assembled correctly even if some parts of it come in after B. So TCP guarantees that messages arrive in one peace (are assembled correctly) but does not guarantee that they come in the order they were sent? TCP guarantees that the messages do arrive in order. The only issue you might have is that described in the link posted earlier, but that is only relevant to multi-threaded applications. If you have a single thread then I can't see why all messages wouldn' be sent atomically. Oscar Hellstr?m-2 wrote: > > Keep in mind that TCP packages can be fragmented on the way, and you need > to assemble them yourself unless you use use the {packet, 1|2|4} option > (and implement that on the flash side), i.e. you need some defined > protocol. > you confused me here a bit. Im using {packet, 4} at the moment, but Im not clear what I would have to do if it were {packet,0}, and what I have to do on the Flash side. The packet assembling would not be handled automatically by the TCP drivers on both Erlang and Flash side? The {packet, 4} adds a four byte header which has the number of bytes in the package (big endian). This means that your client needs to read four bytes, interpret them as an unsigned integer and then read that many bytes to get the whole package. I have no idea if this is built in in flash. If you use {packet, 0} you need to define you own protocol to state the payload of the message, or use some text based protocol where you can figure out if you need to read more or not by reading the message received. Oscar Hellstr?m-2 wrote: > > If you're using a text based protocol this is less of a problem (or more > depending on who you are) I guess. > > From the erlang side we seem to have the same issue that we need to > serialise the data to be absolutely sure that messages are not intervened > (since the inet_drv.c essentially calls send() at some point). Someone > please correct me if I'm wrong here. > > Hope this helps. > > ----- Original Message ----- > From: "deepblue_other" > To: erlang-questions > Sent: Sunday, 5 October, 2008 9:07:08 AM GMT -08:00 US/Canada Pacific > Subject: [erlang-questions] tcp sockets - not clear > > > hello everyone > Im building a system with a Flash front-end and an Erlang back-end and > have > some confusion in a case where there is a single socket on the back-end > per > user (per single socket on the front-end). > I want to have multiple independent objects on the front-end send messages > to the back-end, but am not sure how the simultaneous transmission would > be > handled. This probably stems from my somewhat clowdly understanding of > TCP. > Say there are 3 objects that initiate a send() method on the front-end > (almost at the same time) and send a semi large message each to the > back-end. Each message would be ID'd by the front-end so that when > received > back it can be routed to the appropriate callback. Is this possible? > since the packets are being assembled in the {tcp, Socket, Data} pattern > match, peace by peace, would the correct peaces of the individual messages > be stiched together? (doesnt seem like they would). > > if that wont work then I would just have the serialize the > sending/receiving, which is not too horrible... > > thanks > -- > View this message in context: > http://www.nabble.com/tcp-sockets---not-clear-tp19826070p19826070.html > Sent from the Erlang Questions mailing list archive at Nabble.com. > > Best regards > -- > Oscar Hellstr?m, oscar > Phone: +44 (0)798 45 44 773 > Mobile: +44 (0)207 65 50 337 > Web: http://www.erlang-consulting.com > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -- View this message in context: http://www.nabble.com/tcp-sockets---not-clear-tp19826070p19844239.html Sent from the Erlang Questions mailing list archive at Nabble.com. _______________________________________________ erlang-questions mailing list erlang-questions http://www.erlang.org/mailman/listinfo/erlang-questions -- Oscar Hellstr?m, oscar Phone: +44 (0)798 45 44 773 Mobile: +44 (0)207 65 50 337 Web: http://www.erlang-consulting.com From kenneth.lundin Tue Oct 7 19:30:50 2008 From: kenneth.lundin (Kenneth Lundin) Date: Tue, 7 Oct 2008 19:30:50 +0200 Subject: [erlang-questions] ?DATE and ?TIME MACROs In-Reply-To: References: <48EB2D4D.2060909@gmail.com> <18e4500f-28db-4efd-b399-885fc7ff3e68@l62g2000hse.googlegroups.com> <48EB64A4.90805@gmail.com> Message-ID: module_info ought to be documented somewhere, I actually thought it was. Our general principle is that what is documented is what we support and keep backwards compatible (as much as possible). When it comes to the information you can get out from module_info there are parts that really can be questioned and we have been thinking of changes although they can be made compatible. If we look at M:module_info it returns a list of key value tuples like this: [ {exports,ListOfExportedFunctions}, {imports,ListOfImportedFunctions}, {attributes,ListOfAttributeValues}, {compile,ListOfCompileInfo} ] where ListOfCompileInfo = [ {options,OptionList}, {version,CompilerVersion},{time,CompileDateAndTime},{source,SourceFilePath}] It is the ListOfCompileInfo that in my experience contains questionable information and that we have plans to change. For example {time,CompileTimeAndDate} which contains the time when the compilation was done, this value makes modules (.beam file) different even if they are compiled from exactly the same sources, with the same version of the compiler and with the same compiler options. This is not always a good thing for example if you want to compare beam files and find out which has changed from one version of an application to another. We have thought of 2 alternative solutions. 1) change the time info from compile time to last modification time of the source file 2) introduce a compiler option which can be used to omit the time info completely. The options info has also been questioned since it has a tendency to create large volumes of data. For example if a big project passes a very long and the same list of include directories to every compilation (even if it is not necessary for that particular file). Sometimes the volume of the data here will then be significant compared to the actual code size and the will be kept in RAM by the Erlang VM. We have thought of 2 alternative solutions here too: 1) remove all include paths not used for this file (i.e only keep the ones where we actually included a file). 2) introduce an option with which the info can be suppressed. So in summary. The CompileDateAndTime is a little unsafe to rely on because it might be changed. I actually don't understand why you are interested in ?DATE and ?TIME macros or similar info and I don't see the problem with passing -DDATE or whatever on the command line to erlc. I am sure it is possible on WIndows as well (You can as one example do it with an escript). Even the {source, SourceFilePath } is sometimes totally worthless info and can also make beam files different even though they ought to be identical. /Kenneth Erlang/OTP team, Ericsson On Tue, Oct 7, 2008 at 4:32 PM, harry wrote: > Cheers, > > I had a dig around in the source in compile, and found some other > possible tags. > > But, I wonder, if this is not documented, might it change in the > future? > > On Oct 7, 2:31 pm, Mats Cronqvist wrote: >> harry wrote: >> > Excellent, thanks! >> >> > I'm struggling to find docs on module_info. >> > I'm guessing erlc inserts it into each module >> >> yes. >> >> > and it uses beam_lib? >> >> afaik, no. it's just a regular exported function that would look >> something like this in Erlang. >> >> module_info() -> . >> module_info(Tag) -> >> try proplists:get_value(Tag,module_info()) >> catch _:_ -> exit(badarg) >> end. >> >> where is a constant term. >> this is just speculation on my part though. >> >> mats >> _______________________________________________ >> erlang-questions mailing list >> erlang-questi...://www.erlang.org/mailman/listinfo/erlang-questions > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From 0x6e6562 Tue Oct 7 19:31:56 2008 From: 0x6e6562 (Ben Hood) Date: Tue, 7 Oct 2008 18:31:56 +0100 Subject: [erlang-questions] Some mnesia oddity In-Reply-To: <48EB646E.3080104@ericsson.com> References: <48B7DB67.7010608@erix.ericsson.se> <269388e30810050420w38e3cc77h23dea901c39d6cc1@mail.gmail.com> <48E9BF0F.7080303@erix.ericsson.se> <269388e30810061038u66e36bd9w7aeab7eaafa26449@mail.gmail.com> <48EB0214.5090701@erix.ericsson.se> <269388e30810070058m43b79b33sda220791309291ab@mail.gmail.com> <269388e30810070419n1229dc14sce7fd2e51d65391d@mail.gmail.com> <48EB646E.3080104@ericsson.com> Message-ID: <269388e30810071031g8f202b0xbd5b306b748071c0@mail.gmail.com> Hey Ulf, On Tue, Oct 7, 2008 at 2:30 PM, Ulf Wiger (TN/EAB) wrote: > On replicated tables, using dirty writes or deletes for batch > updates can easily be _less_ efficient (and considerably less > safe) than using transactions. > > The reason is that, if you take a table lock, the overhead > for starting the transaction, acquiring the lock and > committing (where all operations are included in the > commit message), becomes insignificant at some point, > compared to the combined overhead of making an rpc > call for each single operation. This is a very valueable insight, because the tables are actually replicated. The performance I get from the iterating through the table and deleting based on key is less performant than they wildcard option I've been using until now, but it is not unacceptably slower, and is also not using a bug as a feature, so I will go for this option. > Of course, if confronted, I'll deny that > I ever wrote this. ;-) :-) Ben From mats.cronqvist Tue Oct 7 21:14:15 2008 From: mats.cronqvist (Mats Cronqvist) Date: Tue, 07 Oct 2008 21:14:15 +0200 Subject: [erlang-questions] ?DATE and ?TIME MACROs In-Reply-To: References: <48EB2D4D.2060909@gmail.com> <18e4500f-28db-4efd-b399-885fc7ff3e68@l62g2000hse.googlegroups.com> <48EB64A4.90805@gmail.com> Message-ID: <48EBB507.7070709@gmail.com> Kenneth Lundin wrote: > [...] > So in summary. The CompileDateAndTime is a little unsafe to rely on > because it might be changed. > I actually don't understand why you are interested in ?DATE and ?TIME > macros or similar info [...] here's one use case. distel contains this snippet; %%% reload all modules that are out of date %%% compare the compile time of the loaded beam and the beam on disk reload_modules() -> T = fun(L) -> [X || X <- L, element(1,X)==time] end, Tm = fun(M) -> T(M:module_info(compile)) end, Tf = fun(F) -> {ok,{_,[{_,I}]}}=beam_lib:chunks(F,[compile_info]),T(I) end, Load = fun(M) -> c:l(M),M end, [Load(M) || {M,F} <- code:all_loaded(), is_beamfile(F), Tm(M) ok == element(1,file:read_file_info(F)) andalso ".beam" == filename:extension(F). if one manages to penetrate its general horribleness, it does a pretty useful thing; for every loaded beam, compare the compile time with that of the corresponding beam file on disk, and reload the ones that are out of date. this would of course work equally well if erlc stuck the modification time of the erl file into the beam file. mats From mats.cronqvist Tue Oct 7 21:41:24 2008 From: mats.cronqvist (Mats Cronqvist) Date: Tue, 07 Oct 2008 21:41:24 +0200 Subject: [erlang-questions] Get a range of tuples from a Mnesia table In-Reply-To: <6c2563b20810070854u3eb94b79u5c8d90c7b7a4373c@mail.gmail.com> References: <60ed8a460810040919qcf9dd37m994bbf6932f18cc0@mail.gmail.com> <6c2563b20810041111t401ebb0fh5482d383438f0b8b@mail.gmail.com> <48EB1DA3.8030304@gmail.com> <6c2563b20810070854u3eb94b79u5c8d90c7b7a4373c@mail.gmail.com> Message-ID: <48EBBB64.90404@gmail.com> Edwin Fine wrote: > RIght. He did say he was using an ordered_set, and I was imprecise in > saying that it returned the record rather than a one-element list > containing the record. Poetic license :) > A poetic license? That sounds most inconvenient. Have you considered having it removed? mats From rvirding Tue Oct 7 22:09:47 2008 From: rvirding (Robert Virding) Date: Tue, 7 Oct 2008 22:09:47 +0200 Subject: [erlang-questions] re cursive fun() In-Reply-To: <20081007154709.5F69224089@relay.gooddata.com> References: <19820386.post@talk.nabble.com> <48E8892E.5040204@it.uu.se> <8e04b5820810050711s5d4ef554v50131c481fa19e85@mail.gmail.com> <58B11B10-F2AA-4702-A625-A73F9F239A40@cs.otago.ac.nz> <20081007113238.7D4902407D@relay.gooddata.com> <0F3BFEC2F16D4D66A6AF13B05F481CF3@SSI.CORP> <20081007154709.5F69224089@relay.gooddata.com> Message-ID: <3dbc6d1c0810071309w4ee9fbb9o5eaf9c17573aa6@mail.gmail.com> It seems like there are two separate threads here: one is about defining recursive functions in the shell; and the other is about defining local (recursive) functions in a module. The first case has been reasonably covered in how you create a fun with a reference to itself so it can call itself recursively. In the second case I must agree with Richard, there is no *need* to have local (to a function) functions, you can just use normal top-level functions. They *are * more efficient than funs. I have found, however, that I sometimes use funs as local functions when I want to stress that these are local functions. Especially after a bout of LFE hacking which has them. However, if it was really desired it would be possible to add them, of course you would need both the recursive and non-recursive options. It would be a bit of a contrived expression as it would not, *could not*, return anything sensible. I would not like to add a scoping let type construction as we don't have having scoping anywhere else. Well except in funs and comprehensions where the scoping is a bit off actually. The visibility rules for the defined functions would be a bit hairy, very hairy really, but the best would be to make them the same as for variables, which are very hairy. I have no intention of adding an EEP! I don't like the idea of Self. A rather humourous note is local functions in Core erlang. In Core yo have local functions, but only the mutually recursive type. These were originally added to implement comprehensions so only the recursive kind were needed. A solution would be do what I used to threaten Bjarne with: do an E2 and get it right. What ever right is. Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081007/533dcd83/attachment-0001.html From ulf Tue Oct 7 22:36:10 2008 From: ulf (Ulf Wiger) Date: Tue, 7 Oct 2008 22:36:10 +0200 Subject: [erlang-questions] Some mnesia oddity In-Reply-To: <269388e30810071031g8f202b0xbd5b306b748071c0@mail.gmail.com> References: <48B7DB67.7010608@erix.ericsson.se> <269388e30810050420w38e3cc77h23dea901c39d6cc1@mail.gmail.com> <48E9BF0F.7080303@erix.ericsson.se> <269388e30810061038u66e36bd9w7aeab7eaafa26449@mail.gmail.com> <48EB0214.5090701@erix.ericsson.se> <269388e30810070058m43b79b33sda220791309291ab@mail.gmail.com> <269388e30810070419n1229dc14sce7fd2e51d65391d@mail.gmail.com> <48EB646E.3080104@ericsson.com> <269388e30810071031g8f202b0xbd5b306b748071c0@mail.gmail.com> Message-ID: <8209f740810071336j7044ce1eyaea6ed19aea8e1fc@mail.gmail.com> Ok, so a good rule of thumb: Don't use dirty updates on replicated tables. http://www.erlang.org/pipermail/erlang-questions/2006-February/019092.html BR, Ulf W 2008/10/7 Ben Hood <0x6e6562>: > Hey Ulf, > > On Tue, Oct 7, 2008 at 2:30 PM, Ulf Wiger (TN/EAB) > wrote: >> On replicated tables, using dirty writes or deletes for batch >> updates can easily be _less_ efficient (and considerably less >> safe) than using transactions. >> >> The reason is that, if you take a table lock, the overhead >> for starting the transaction, acquiring the lock and >> committing (where all operations are included in the >> commit message), becomes insignificant at some point, >> compared to the combined overhead of making an rpc >> call for each single operation. > > This is a very valueable insight, because the tables are actually replicated. > > The performance I get from the iterating through the table and > deleting based on key is less performant than they wildcard option > I've been using until now, but it is not unacceptably slower, and is > also not using a bug as a feature, so I will go for this option. > >> Of course, if confronted, I'll deny that >> I ever wrote this. ;-) > > :-) > > Ben > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From erlang-questions_efine Tue Oct 7 22:46:43 2008 From: erlang-questions_efine (Edwin Fine) Date: Tue, 7 Oct 2008 16:46:43 -0400 Subject: [erlang-questions] ?DATE and ?TIME MACROs In-Reply-To: References: <48EB2D4D.2060909@gmail.com> <18e4500f-28db-4efd-b399-885fc7ff3e68@l62g2000hse.googlegroups.com> <48EB64A4.90805@gmail.com> Message-ID: <6c2563b20810071346q1c7aa889r7fa8b24a40275068@mail.gmail.com> Kenneth, I find module_info's {time,CompileTimeAndDate} very useful. At a glance, I can see whether a set of modules that were recently compiled made it to the target platform properly after distribution and installation. Unlike Erlang/OTP itself, the applications I am working with have frequent releases, and sometimes things can go wrong with the distribution mechanism (yes, I know, fix the mechanism, but I still like to have to ability to check). When that happens, I like to be able to look at a beam on the target system and see its compile date and time, and compare it with the known good date and time. A checksum would work just as well for pure comparison purposes but contains less information - a date/time is very human-friendly. The date of the actual beam is, I feel, somewhat more useful (to me, anyway) than the date of the source file, because when I release something I usually rebuild everything from scratch and want to see the *build* date and time in the beam files, not necessarily the *source* date and time. My vote, for what it's worth, is to keep {time,CompileTimeAndDate} and add the compile option to suppress it if it really annoys people. By the way, if module_info is documented somewhere, could some kind person please point me to it because I looked for it in the Erlang docs last night and could not find it. Not saying it's not there, just I couldn't find it. It wasn't in the permuted indexes, either. Regards, Edwin Fine On Tue, Oct 7, 2008 at 1:30 PM, Kenneth Lundin wrote: > module_info ought to be documented somewhere, I actually thought it was. > Our general principle is that what is documented is what we support > and keep backwards compatible (as much as possible). > When it comes to the information you can get out from module_info > there are parts that really can be questioned and we > have been thinking of changes although they can be made compatible. > > If we look at M:module_info it returns a list of key value tuples like > this: > [ > {exports,ListOfExportedFunctions}, > {imports,ListOfImportedFunctions}, > {attributes,ListOfAttributeValues}, > {compile,ListOfCompileInfo} > ] > > where ListOfCompileInfo = [ {options,OptionList}, > > {version,CompilerVersion},{time,CompileDateAndTime},{source,SourceFilePath}] > > It is the ListOfCompileInfo that in my experience contains > questionable information and that we have plans to change. > For example {time,CompileTimeAndDate} which contains the time when the > compilation was done, this value makes modules (.beam file) > different even if they are compiled from exactly the same sources, > with the same version of the compiler and with the same compiler > options. This is not always a good thing for example if you want to > compare beam files and find out which has changed from one > version of an application to another. > We have thought of 2 alternative solutions. 1) change the time info > from compile time to last modification time of the source file > 2) introduce a compiler option which can be used to omit the time info > completely. > > The options info has also been questioned since it has a tendency to > create large volumes of data. For example if a big project passes a > very long and the same list of include directories to every > compilation (even if it is not necessary for that particular file). > Sometimes the volume of the data here will then be significant > compared to the actual code size and the will be kept in RAM by the > Erlang VM. > We have thought of 2 alternative solutions here too: 1) remove all > include paths not used for this file (i.e only keep the ones where > we actually included a file). 2) introduce an option with which the > info can be suppressed. > > > So in summary. The CompileDateAndTime is a little unsafe to rely on > because it might be changed. > > I actually don't understand why you are interested in ?DATE and ?TIME > macros or similar info and I don't see the problem with > passing -DDATE or whatever on the command line to erlc. I am sure it > is possible on WIndows as well (You can as one example > do it with an escript). > > > Even the {source, SourceFilePath } is sometimes totally worthless info > and can also make beam files different even though > they ought to be identical. > > /Kenneth Erlang/OTP team, Ericsson > > > > On Tue, Oct 7, 2008 at 4:32 PM, harry wrote: > > Cheers, > > > > I had a dig around in the source in compile, and found some other > > possible tags. > > > > But, I wonder, if this is not documented, might it change in the > > future? > > > > On Oct 7, 2:31 pm, Mats Cronqvist wrote: > >> harry wrote: > >> > Excellent, thanks! > >> > >> > I'm struggling to find docs on module_info. > >> > I'm guessing erlc inserts it into each module > >> > >> yes. > >> > >> > and it uses beam_lib? > >> > >> afaik, no. it's just a regular exported function that would look > >> something like this in Erlang. > >> > >> module_info() -> . > >> module_info(Tag) -> > >> try proplists:get_value(Tag,module_info()) > >> catch _:_ -> exit(badarg) > >> end. > >> > >> where is a constant term. > >> this is just speculation on my part though. > >> > >> mats > >> _______________________________________________ > >> erlang-questions mailing list > >> erlang-questi...:// > www.erlang.org/mailman/listinfo/erlang-questions > > _______________________________________________ > > erlang-questions mailing list > > erlang-questions > > http://www.erlang.org/mailman/listinfo/erlang-questions > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081007/2c344779/attachment.html From mpharrison Wed Oct 8 00:39:29 2008 From: mpharrison (harry) Date: Tue, 7 Oct 2008 15:39:29 -0700 (PDT) Subject: [erlang-questions] ?DATE and ?TIME MACROs In-Reply-To: <6c2563b20810071346q1c7aa889r7fa8b24a40275068@mail.gmail.com> References: <48EB2D4D.2060909@gmail.com> <18e4500f-28db-4efd-b399-885fc7ff3e68@l62g2000hse.googlegroups.com> <48EB64A4.90805@gmail.com> <6c2563b20810071346q1c7aa889r7fa8b24a40275068@mail.gmail.com> Message-ID: the only reference I could find was in the page for xref, and it doesn't say a whole lot, apart from saying the compiler inserts the function. On Oct 7, 9:46?pm, "Edwin Fine" wrote: > Kenneth, > > I find module_info's {time,CompileTimeAndDate} very useful. At a glance, I > can see whether a set of modules that were recently compiled made it to the > target platform properly after distribution and installation. Unlike > Erlang/OTP itself, the applications I am working with have frequent > releases, and sometimes things can go wrong with the distribution mechanism > (yes, I know, fix the mechanism, but I still like to have to ability to > check). When that happens, I like to be able to look at a beam on the target > system and see its compile date and time, and compare it with the known good > date and time. A checksum would work just as well for pure comparison > purposes but contains less information - a date/time is very human-friendly. > The date of the actual beam is, I feel, somewhat more useful (to me, anyway) > than the date of the source file, because when I release something I usually > rebuild everything from scratch and want to see the *build* date and time in > the beam files, not necessarily the *source* date and time. > > My vote, for what it's worth, is to keep {time,CompileTimeAndDate} and add > the compile option to suppress it if it really annoys people. > > By the way, if module_info is documented somewhere, could some kind person > please point me to it because I looked for it in the Erlang docs last night > and could not find it. Not saying it's not there, just I couldn't find it. > It wasn't in the permuted indexes, either. > > Regards, > Edwin Fine > > On Tue, Oct 7, 2008 at 1:30 PM, Kenneth Lundin wrote: > > > module_info ought to be documented somewhere, I actually thought it was. > > Our general principle is that what is documented is what we support > > and keep backwards compatible (as much as possible). > > When it comes to the information you can get out from module_info > > there are parts that really can be questioned and we > > have been thinking of changes although they can be made compatible. > > > If we look at M:module_info it returns a list of key value tuples like > > this: > > [ > > ?{exports,ListOfExportedFunctions}, > > ?{imports,ListOfImportedFunctions}, > > ?{attributes,ListOfAttributeValues}, > > ?{compile,ListOfCompileInfo} > > ] > > > where ListOfCompileInfo = [ {options,OptionList}, > > > {version,CompilerVersion},{time,CompileDateAndTime},{source,SourceFilePath}] > > > It is the ListOfCompileInfo that in my experience contains > > questionable information and that we have plans to change. > > For example {time,CompileTimeAndDate} which contains the time when the > > compilation was done, this value makes modules (.beam file) > > different even if they are compiled from exactly the same sources, > > with the same version of the compiler and with the same compiler > > options. This is not always a good thing for example if you want to > > compare beam files and find out which has changed from one > > version of an application to another. > > We have thought of 2 alternative solutions. 1) change the time info > > from compile time to last modification time of the source file > > 2) introduce a compiler option which can be used to omit the time info > > completely. > > > The options info has also been questioned since it has a tendency to > > create large volumes of data. For example if a big project passes a > > very long and the same list of include directories to every > > compilation (even if it is not necessary for that particular file). > > Sometimes the volume of the data here will then be significant > > compared to the actual code size and the will be kept in RAM by the > > Erlang VM. > > We have thought of 2 alternative solutions here too: 1) remove all > > include paths not used for this file (i.e only keep the ones where > > we actually included a file). 2) introduce an option with which the > > info can be suppressed. > > > So in summary. The CompileDateAndTime is a little unsafe to rely on > > because it might be changed. > > > I actually don't understand why you are interested in ?DATE and ?TIME > > macros or similar info and I don't see the problem with > > passing -DDATE or whatever on the command line to erlc. I am sure it > > is possible on WIndows as well (You can as one example > > do it with an escript). > > > Even the {source, SourceFilePath } is sometimes totally worthless info > > and can also make beam files different even though > > they ought to be identical. > > > /Kenneth Erlang/OTP team, Ericsson > > > On Tue, Oct 7, 2008 at 4:32 PM, harry wrote: > > > Cheers, > > > > I had a dig around in the source in compile, and found some other > > > possible tags. > > > > But, I wonder, if this is not documented, might it change in the > > > future? > > > > On Oct 7, 2:31 pm, Mats Cronqvist wrote: > > >> harry wrote: > > >> > Excellent, thanks! > > > >> > I'm struggling to find docs on module_info. > > >> > I'm guessing erlc inserts it into each module > > > >> yes. > > > >> > and it uses beam_lib? > > > >> ?afaik, no. it's just a regular exported function that would look > > >> something like this in Erlang. > > > >> module_info() -> . > > >> module_info(Tag) -> > > >> ?try proplists:get_value(Tag,module_info()) > > >> ?catch _:_ -> exit(badarg) > > >> ?end. > > > >> ?where is a constant term. > > >> ?this is just speculation on my part though. > > > >> ? mats > > >> _______________________________________________ > > >> erlang-questions mailing list > > >> erlang-questi...:// > >www.erlang.org/mailman/listinfo/erlang-questions > > > _______________________________________________ > > > erlang-questions mailing list > > > erlang-questi... > > >http://www.erlang.org/mailman/listinfo/erlang-questions > > > _______________________________________________ > > erlang-questions mailing list > > erlang-questi... > >http://www.erlang.org/mailman/listinfo/erlang-questions > > > > _______________________________________________ > erlang-questions mailing list > erlang-questi...://www.erlang.org/mailman/listinfo/erlang-questions From bengt.kleberg Wed Oct 8 07:33:22 2008 From: bengt.kleberg (Bengt Kleberg) Date: Wed, 08 Oct 2008 07:33:22 +0200 Subject: [erlang-questions] Get a range of tuples from a Mnesia table In-Reply-To: <48EBBB64.90404@gmail.com> References: <60ed8a460810040919qcf9dd37m994bbf6932f18cc0@mail.gmail.com> <6c2563b20810041111t401ebb0fh5482d383438f0b8b@mail.gmail.com> <48EB1DA3.8030304@gmail.com> <6c2563b20810070854u3eb94b79u5c8d90c7b7a4373c@mail.gmail.com> <48EBBB64.90404@gmail.com> Message-ID: <1223444002.3831.3.camel@seasc0642.dyn.rnd.as.sw.ericsson.se> If he then continues without a license, would that make him an underground poet? bengt On Tue, 2008-10-07 at 21:41 +0200, Mats Cronqvist wrote: > Edwin Fine wrote: > > RIght. He did say he was using an ordered_set, and I was imprecise in > > saying that it returned the record rather than a one-element list > > containing the record. Poetic license :) > > > A poetic license? That sounds most inconvenient. Have you considered > having it removed? > > mats > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions From richardc Wed Oct 8 08:41:51 2008 From: richardc (Richard Carlsson) Date: Wed, 08 Oct 2008 08:41:51 +0200 Subject: [erlang-questions] ?DATE and ?TIME MACROs In-Reply-To: References: Message-ID: <48EC562F.7060408@it.uu.se> harry wrote: > How would you do ?DATE and ?TIME (apart from erlc -DDATE=`time` .... > or something similar, which is *nix specific) > > Would there be any mileage in adding these (and ?FUNCTION) to epp? DATE and TIME could easily be added to epp, as long as one can still override the definitions from the command line with -D to set a global time and date for the entire build. FUNCTION, however, does not really belong in the preprocessor, because it can never be expanded at preprocessing time to a literal (so that you can e.g. use it in a pattern); it must expand to a runtime call. In that case you might as well use that function call instead of the macro. /Richard From 0x6e6562 Wed Oct 8 08:41:45 2008 From: 0x6e6562 (Ben Hood) Date: Wed, 8 Oct 2008 07:41:45 +0100 Subject: [erlang-questions] Some mnesia oddity In-Reply-To: <48EC4E3A.6040601@erix.ericsson.se> References: <269388e30810050420w38e3cc77h23dea901c39d6cc1@mail.gmail.com> <48E9BF0F.7080303@erix.ericsson.se> <269388e30810061038u66e36bd9w7aeab7eaafa26449@mail.gmail.com> <48EB0214.5090701@erix.ericsson.se> <269388e30810070058m43b79b33sda220791309291ab@mail.gmail.com> <269388e30810070419n1229dc14sce7fd2e51d65391d@mail.gmail.com> <48EB646E.3080104@ericsson.com> <269388e30810071031g8f202b0xbd5b306b748071c0@mail.gmail.com> <48EC4E3A.6040601@erix.ericsson.se> Message-ID: <269388e30810072341q19bf551bh4b912b053f78611d@mail.gmail.com> Dan, On Wed, Oct 8, 2008 at 7:07 AM, Dan Gudmundsson wrote: > Hey, tought about this when I walked here to work. > > You do take a write table lock before your loop, right. > Because otherwise you loose a lot of roundtrip time, which > wasn't in the delete_object it only gets a lock on the {Tab,Key} > record. Are you suggesting that I get a lock on the whole table before I start iterating through it instead of just getting a record lock for each object on every iteration? If so, I'll give that a go and see what difference it makes. Thx, Ben From vychodil.hynek Wed Oct 8 09:41:31 2008 From: vychodil.hynek (Hynek Vychodil) Date: Wed, 8 Oct 2008 09:41:31 +0200 Subject: [erlang-questions] re cursive fun() In-Reply-To: <3dbc6d1c0810071309w4ee9fbb9o5eaf9c17573aa6@mail.gmail.com> References: <19820386.post@talk.nabble.com> <48E8892E.5040204@it.uu.se> <8e04b5820810050711s5d4ef554v50131c481fa19e85@mail.gmail.com> <58B11B10-F2AA-4702-A625-A73F9F239A40@cs.otago.ac.nz> <20081007113238.7D4902407D@relay.gooddata.com> <0F3BFEC2F16D4D66A6AF13B05F481CF3@SSI.CORP> <20081007154709.5F69224089@relay.gooddata.com> <3dbc6d1c0810071309w4ee9fbb9o5eaf9c17573aa6@mail.gmail.com> Message-ID: <20081008074132.407B22407D@relay.gooddata.com> On Tue, Oct 7, 2008 at 10:09 PM, Robert Virding wrote: > It seems like there are two separate threads here: one is about defining > recursive functions in the shell; and the other is about defining local > (recursive) functions in a module. > You can use same tricks in module as in shell (if you are pervert a little ;-). > > > The first case has been reasonably covered in how you create a fun with a > reference to itself so it can call itself recursively. > > In the second case I must agree with Richard, there is no *need* to have > local (to a function) functions, you can just use normal top-level > functions. They *are * more efficient than funs. I have found, however, that > I sometimes use funs as local functions when I want to stress that these are > local functions. Especially after a bout of LFE hacking which has them. > I agree, there is always way how to do refactoring to local recursive functions and make up funs from those. (There should not be difference in performance, it is Erlang fault if is. But there is long way to this goal, for example hot spot compiler and such thinks.) I strongly agree with following, especially with EPP and Self thinks. > > > However, if it was really desired it would be possible to add them, of > course you would need both the recursive and non-recursive options. It would > be a bit of a contrived expression as it would not, *could not*, return > anything sensible. I would not like to add a scoping let type construction > as we don't have having scoping anywhere else. Well except in funs and > comprehensions where the scoping is a bit off actually. The visibility rules > for the defined functions would be a bit hairy, very hairy really, but the > best would be to make them the same as for variables, which are very hairy. > > I have no intention of adding an EEP! > > I don't like the idea of Self. > > A rather humourous note is local functions in Core erlang. In Core yo have > local functions, but only the mutually recursive type. These were originally > added to implement comprehensions so only the recursive kind were needed. > > A solution would be do what I used to threaten Bjarne with: do an E2 and > get it right. What ever right is. > > Robert > > -- --Hynek (Pichi) Vychodil -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081008/fdd933d5/attachment.html From 0x6e6562 Wed Oct 8 11:55:52 2008 From: 0x6e6562 (Ben Hood) Date: Wed, 8 Oct 2008 10:55:52 +0100 Subject: [erlang-questions] Some mnesia oddity In-Reply-To: <269388e30810072341q19bf551bh4b912b053f78611d@mail.gmail.com> References: <48E9BF0F.7080303@erix.ericsson.se> <269388e30810061038u66e36bd9w7aeab7eaafa26449@mail.gmail.com> <48EB0214.5090701@erix.ericsson.se> <269388e30810070058m43b79b33sda220791309291ab@mail.gmail.com> <269388e30810070419n1229dc14sce7fd2e51d65391d@mail.gmail.com> <48EB646E.3080104@ericsson.com> <269388e30810071031g8f202b0xbd5b306b748071c0@mail.gmail.com> <48EC4E3A.6040601@erix.ericsson.se> <269388e30810072341q19bf551bh4b912b053f78611d@mail.gmail.com> Message-ID: <269388e30810080255n77f78dc4jc1a0b43ba024129c@mail.gmail.com> Dan, On Wed, Oct 8, 2008 at 7:41 AM, Ben Hood <0x6e6562> wrote: >> You do take a write table lock before your loop, right. >> Because otherwise you loose a lot of roundtrip time, which >> wasn't in the delete_object it only gets a lock on the {Tab,Key} >> record. > > Are you suggesting that I get a lock on the whole table before I start > iterating through it instead of just getting a record lock for each > object on every iteration? > > If so, I'll give that a go and see what difference it makes. I've just tried locking the whole table and it effectively doubles the rate of deletion when looping through the table and deleting records based on their keys. Now I need to consider whether a full table lock is acceptable for my particular application, but at least I now know what effect the different ways of deleting records from mnesia have. Thanks for your help, Ben From saleyn Wed Oct 8 14:36:59 2008 From: saleyn (Serge Aleynikov) Date: Wed, 08 Oct 2008 08:36:59 -0400 Subject: [erlang-questions] jinterface In-Reply-To: <3dbc6d1c0810040757u795d521ex4223ad37a4ab3900@mail.gmail.com> References: <6C2A5378-5BDE-4FF9-B2AF-790D1F78330B@kallisys.net> <48E7730B.3090506@gmail.com> <3dbc6d1c0810040711w26eae030pbcbccf7e1f4d5fd0@mail.gmail.com> <48E78277.4000809@gmail.com> <3dbc6d1c0810040757u795d521ex4223ad37a4ab3900@mail.gmail.com> Message-ID: <48ECA96B.2030201@gmail.com> Last weekend I did implement support for monitoring Erlang pids in otp.net. It seems to work ok, though I see Vlad's point in that it's somewhat cumbersome to use Erlang-style message passing in a language that doesn't support native concurrency. I faced another "challenge" being that the IO requests in the form of io:format(Fmt, Args) get directed to a group leader in the otp.net node as an io_request carrying some {put_chars, io_lib, format, Args} content. The inconvenience is that otp.net node doesn't have any clue of how apply that io:format/2 function to format that output. Is there a way to force the evaluation to happen on the Erlang side so that it would come to the non-Erlang node as {put_chars, String} of some sort? Serge Robert Virding wrote: > That would be a better solution in the long-run, but it is one which, > unfortunately, I can't help you with. > > Robert > > 2008/10/4 Serge Aleynikov > >> Ah, I see, this makes sense. Meanwhile, I looked through the distribution >> sources, ei, and jinterface and see that it's not that difficult to add some >> monitoring support for non-Erlang nodes so that they can monitor Erlang >> pids. I'll patch otp.net and later ei if I find time this or next >> weekend. >> >> Serge >> >> >> Robert Virding wrote: >> >>> It's not the io server which tries to setup a monitor, but the io module >>> itself. These are two separate but cooperating entities. The io module >>> monitors the io server to make sure that the call will not block if the >>> process dies. The easiest way around this is to do the send/receive to the >>> io serv yourself without a monitor. >>> >>> Robert >>> >>> 2008/10/4 Serge Aleynikov >>> >>> One other "nasty" feature is that any attempt to make an RPC call of >>>> io:format/2 from a Java/.NET node fails with badarg, because io server >>>> tries to set up a monitor to the remote pid and fails miserably... >>>> >>>> Actually I see what's missing in Java/OTP.NET implementation. These >>>> features are documented here: >>>> http://www.erlang.org/doc/apps/erts/erl_dist_protocol.html#9.7 >>>> >>>> Serge >>>> >>>> >>>> >>>> Paul Guyot wrote: >>>> >>>>> Date: Sat, 04 Oct 2008 01:32:55 -0400 >>>>>> From: Serge Aleynikov >>>>>> Subject: Re: [erlang-questions] jinterface (was: otp.net) >>>>>> >>>>>> I tried a similar test using jinterface to see if it's possible to >>>>>> monitor processes running on a Java node and ran into the same failure. >>>>>> >>>>>> Can anyone explain what's wrong? >>>>>> >>>>>> (server)10> {test, client} ! {self(), hello}. >>>>>> {<0.45.0>,hello} >>>>>> (server)11> f(), {Pid, _} = receive M -> M end. >>>>>> {<5979.1.0>,hello} >>>>>> (server)12> erlang:monitor(process, Pid). >>>>>> ** exception error: bad argument >>>>>> in function erlang:monitor/2 >>>>>> called as erlang:monitor(process,<5979.1.0>) >>>>>> >>>>> I've seen a comment in stdlib/gen.erl, at line 196, that suggests that >>>>> Java and C nodes are featureweak, and processes in such nodes cannot be >>>>> monitored. Instead, you have to monitor the whole node with >>>>> monitor_node/2. This makes sense because the OTP ei (C library) or >>>>> jinterface do not monitor "processes". Indeed, there is only one pid per >>>>> node, which is the node's pseudo-pid (even if technically, each >>>>> connection can receive messages). I guess you can draw from the code in >>>>> gen.erl if you need to monitor either an erlang process or your java >>>>> process, or just monitor the node if you only need to monitor java >>>>> processes. >>>>> >>>>> Regards, >>>>> >>>>> Paul >>>>> >>>>> >>>>> _______________________________________________ >>>> erlang-questions mailing list >>>> erlang-questions >>>> http://www.erlang.org/mailman/listinfo/erlang-questions >>>> >>>> > From rasmussen.bryan Wed Oct 8 15:07:07 2008 From: rasmussen.bryan (bryan rasmussen) Date: Wed, 8 Oct 2008 15:07:07 +0200 Subject: [erlang-questions] Erlang with MonetDb In-Reply-To: <6a36e7290810070934k1a3fbf43k258c6220b6a56e75@mail.gmail.com> References: <3bb44c6e0810070454s5cd3a829p524ce628808a2323@mail.gmail.com> <6a36e7290810070934k1a3fbf43k258c6220b6a56e75@mail.gmail.com> Message-ID: <3bb44c6e0810080607m21ce8ef3o2d8fdfc054a9346d@mail.gmail.com> Damn. I was worried about that myself, I've already had some problems in the initial testing that make me not want to trust important data to it. Well, in case it turns out we don't want to use it does anyone have a good column store that they can recommend to use in conjunction with Erlang? Cheers, Bryan Rasmussen On Tue, Oct 7, 2008 at 6:34 PM, Bob Ippolito wrote: > I don't have an answer for you, but we tried using MonetDB early this > year and it was an epic failure, the database corrupted itself and at > times the server would grow until it ran out of RAM. We unfortunately > had to resort to a commercial column store because we couldn't get > MonetDB to run for more than a few hours without crashing :( > > On Tue, Oct 7, 2008 at 4:54 AM, bryan rasmussen > wrote: >> Hi, >> >> Anyone out there made some erlang examples working with MonetDB? using >> ODBC acceptable. >> >> >> Cheers, >> Bryan Rasmussen >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions >> http://www.erlang.org/mailman/listinfo/erlang-questions >> > From rvirding Wed Oct 8 15:57:14 2008 From: rvirding (Robert Virding) Date: Wed, 8 Oct 2008 15:57:14 +0200 Subject: [erlang-questions] jinterface In-Reply-To: <48ECA96B.2030201@gmail.com> References: <6C2A5378-5BDE-4FF9-B2AF-790D1F78330B@kallisys.net> <48E7730B.3090506@gmail.com> <3dbc6d1c0810040711w26eae030pbcbccf7e1f4d5fd0@mail.gmail.com> <48E78277.4000809@gmail.com> <3dbc6d1c0810040757u795d521ex4223ad37a4ab3900@mail.gmail.com> <48ECA96B.2030201@gmail.com> Message-ID: <3dbc6d1c0810080657u4891111cr2052dc90488290f8@mail.gmail.com> Yes, it is easy to get around this, but no it is not. The io module was designed to send the formatting computations to the io-server to be done there. The group leader is an io-server as well as being group leader (see my Erlang Rationale for a bit better explanation). As I see it you have the following options: - Do not use io:fwrite or other formatting io calls directly but instead do io:put_chars(io_lib:fwrite(Fmt, Args)) instead. This ensures that only an iolist is sent to the group leader. - Modify io.erl to do this for automatically for you and use this private version. This is not difficult and should cause no other problems. - Modify your program so that you start a local group leader/io-server which does the formatting and just send the output iolists to the otp.net process. Do you do any input from otp.net? If so you will have to do the last option and fix the otp.net process a bit. I hope this helps, Robert 2008/10/8 Serge Aleynikov > Last weekend I did implement support for monitoring Erlang pids in otp.net. > It seems to work ok, though I see Vlad's point in that it's somewhat > cumbersome to use Erlang-style message passing in a language that doesn't > support native concurrency. > > I faced another "challenge" being that the IO requests in the form of > io:format(Fmt, Args) get directed to a group leader in the otp.net node as > an io_request carrying some {put_chars, io_lib, format, Args} content. The > inconvenience is that otp.net node doesn't have any clue of how apply that > io:format/2 function to format that output. Is there a way to force the > evaluation to happen on the Erlang side so that it would come to the > non-Erlang node as {put_chars, String} of some sort? > > Serge > > Robert Virding wrote: > >> That would be a better solution in the long-run, but it is one which, >> unfortunately, I can't help you with. >> >> Robert >> >> 2008/10/4 Serge Aleynikov >> >> Ah, I see, this makes sense. Meanwhile, I looked through the >>> distribution >>> sources, ei, and jinterface and see that it's not that difficult to add >>> some >>> monitoring support for non-Erlang nodes so that they can monitor Erlang >>> pids. I'll patch otp.net and later ei if I find time this or next >>> weekend. >>> >>> Serge >>> >>> >>> Robert Virding wrote: >>> >>> It's not the io server which tries to setup a monitor, but the io module >>>> itself. These are two separate but cooperating entities. The io module >>>> monitors the io server to make sure that the call will not block if the >>>> process dies. The easiest way around this is to do the send/receive to >>>> the >>>> io serv yourself without a monitor. >>>> >>>> Robert >>>> >>>> 2008/10/4 Serge Aleynikov >>>> >>>> One other "nasty" feature is that any attempt to make an RPC call of >>>> >>>>> io:format/2 from a Java/.NET node fails with badarg, because io server >>>>> tries to set up a monitor to the remote pid and fails miserably... >>>>> >>>>> Actually I see what's missing in Java/OTP.NET implementation. These >>>>> features are documented here: >>>>> http://www.erlang.org/doc/apps/erts/erl_dist_protocol.html#9.7 >>>>> >>>>> Serge >>>>> >>>>> >>>>> >>>>> Paul Guyot wrote: >>>>> >>>>> Date: Sat, 04 Oct 2008 01:32:55 -0400 >>>>>> >>>>>>> From: Serge Aleynikov >>>>>>> Subject: Re: [erlang-questions] jinterface (was: otp.net) >>>>>>> >>>>>>> I tried a similar test using jinterface to see if it's possible to >>>>>>> monitor processes running on a Java node and ran into the same >>>>>>> failure. >>>>>>> >>>>>>> Can anyone explain what's wrong? >>>>>>> >>>>>>> (server)10> {test, client} ! {self(), hello}. >>>>>>> {<0.45.0>,hello} >>>>>>> (server)11> f(), {Pid, _} = receive M -> M end. >>>>>>> {<5979.1.0>,hello} >>>>>>> (server)12> erlang:monitor(process, Pid). >>>>>>> ** exception error: bad argument >>>>>>> in function erlang:monitor/2 >>>>>>> called as erlang:monitor(process,<5979.1.0>) >>>>>>> >>>>>>> I've seen a comment in stdlib/gen.erl, at line 196, that suggests >>>>>> that >>>>>> Java and C nodes are featureweak, and processes in such nodes cannot >>>>>> be >>>>>> monitored. Instead, you have to monitor the whole node with >>>>>> monitor_node/2. This makes sense because the OTP ei (C library) or >>>>>> jinterface do not monitor "processes". Indeed, there is only one pid >>>>>> per >>>>>> node, which is the node's pseudo-pid (even if technically, each >>>>>> connection can receive messages). I guess you can draw from the code >>>>>> in >>>>>> gen.erl if you need to monitor either an erlang process or your java >>>>>> process, or just monitor the node if you only need to monitor java >>>>>> processes. >>>>>> >>>>>> Regards, >>>>>> >>>>>> Paul >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> >>>>> erlang-questions mailing list >>>>> erlang-questions >>>>> http://www.erlang.org/mailman/listinfo/erlang-questions >>>>> >>>>> >>>>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081008/2f81deb1/attachment.html From joelr1 Wed Oct 8 18:01:25 2008 From: joelr1 (Joel Reymont) Date: Wed, 8 Oct 2008 17:01:25 +0100 Subject: [erlang-questions] pid to integer and back Message-ID: Is there a safe and efficient way to convert pid to integer and back? I'm assigning each running poker game an integer id. I store this id into every outgoing packet so there's no database lookup. I use the id to lookup the game process for every incoming packet, though. This is proving to be extremely inefficient, even with dirty mnesia reads. I actually repeat the above for every player, so there's twice the overhead. Is there a way to avoid it? This would only apply to running games and connected players so this would be a temporary integer, valid while the process is alive. Thanks, Joel -- wagerlabs.com From pfisher Wed Oct 8 18:08:30 2008 From: pfisher (Paul Fisher) Date: Wed, 08 Oct 2008 11:08:30 -0500 Subject: [erlang-questions] pid to integer and back In-Reply-To: References: Message-ID: <48ECDAFE.5020205@alertlogic.net> Joel Reymont wrote: > Is there a safe and efficient way to convert pid to integer and back? Does it really need to be an integer? Can you do a fixed size binary (e.g. term_to_binary(pid()))? -- paul From joelr1 Wed Oct 8 18:13:50 2008 From: joelr1 (Joel Reymont) Date: Wed, 8 Oct 2008 17:13:50 +0100 Subject: [erlang-questions] pid to integer and back In-Reply-To: <48ECDAFE.5020205@alertlogic.net> References: <48ECDAFE.5020205@alertlogic.net> Message-ID: Paul, That's quite rich at 27 bytes. I would prefer 12 (4x3). Thanks, Joel On Oct 8, 2008, at 5:08 PM, Paul Fisher wrote: > Does it really need to be an integer? Can you do a fixed size > binary (e.g. term_to_binary(pid()))? -- wagerlabs.com From vychodil.hynek Wed Oct 8 18:14:05 2008 From: vychodil.hynek (Hynek Vychodil) Date: Wed, 8 Oct 2008 18:14:05 +0200 Subject: [erlang-questions] pid to integer and back In-Reply-To: References: Message-ID: <20081008161406.5E94024022@relay.gooddata.com> And what about term_to_binary? On Wed, Oct 8, 2008 at 6:01 PM, Joel Reymont wrote: > Is there a safe and efficient way to convert pid to integer and back? > > I'm assigning each running poker game an integer id. I store this id > into every outgoing packet so there's no database lookup. > > I use the id to lookup the game process for every incoming packet, > though. This is proving to be extremely inefficient, even with dirty > mnesia reads. > > I actually repeat the above for every player, so there's twice the > overhead. Is there a way to avoid it? > > This would only apply to running games and connected players so this > would be a temporary integer, valid while the process is alive. > > Thanks, Joel > > -- > wagerlabs.com > > > > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -- --Hynek (Pichi) Vychodil -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081008/4f4aab32/attachment-0001.html From joelr1 Wed Oct 8 18:16:36 2008 From: joelr1 (Joel Reymont) Date: Wed, 8 Oct 2008 17:16:36 +0100 Subject: [erlang-questions] pid to integer and back In-Reply-To: <20081008161406.6F7D12402F@relay.gooddata.com> References: <20081008161406.6F7D12402F@relay.gooddata.com> Message-ID: On Oct 8, 2008, at 5:14 PM, Hynek Vychodil wrote: > And what about term_to_binary? My current encoding uses 4 bytes. term_to_binary uses 27. I would prefer something closer to 4 bytes since term_to_binary would be effectively doubling or tripling the size of every packet. Thanks, Joel -- wagerlabs.com From joelr1 Wed Oct 8 18:24:22 2008 From: joelr1 (Joel Reymont) Date: Wed, 8 Oct 2008 17:24:22 +0100 Subject: [erlang-questions] pid to integer and back In-Reply-To: <20081008161406.6F7D12402F@relay.gooddata.com> References: <20081008161406.6F7D12402F@relay.gooddata.com> Message-ID: I know you can put pids back together with c:pid(X, Y, Z). How do you take a triple apart, though, without using pid_to_list and parsing the string? Thanks, Joel -- wagerlabs.com From mpharrison Wed Oct 8 18:26:57 2008 From: mpharrison (harry) Date: Wed, 8 Oct 2008 09:26:57 -0700 (PDT) Subject: [erlang-questions] ?DATE and ?TIME MACROs In-Reply-To: <48EC562F.7060408@it.uu.se> References: <48EC562F.7060408@it.uu.se> Message-ID: <04e6df18-568b-44be-8710-b47d4f16623d@t41g2000hsc.googlegroups.com> Thanks all for your replies. ?DATE & ?TIME would be convenient if they were added to epp as you suggest. Then it would match cpp's __DATE__ and __TIME__. Although one can always use erlc -DDATE etc, as suggested above. On Oct 8, 7:41?am, Richard Carlsson wrote: > harry wrote: > DATE and TIME could easily be added to epp, as long as one can still > override the definitions from the command line with -D to set a global > time and date for the entire build. > > FUNCTION, however, does not really belong in the preprocessor, ... I suppose because of inlining? - I saw something like that in my searches. From bob Wed Oct 8 18:45:52 2008 From: bob (Bob Ippolito) Date: Wed, 8 Oct 2008 12:45:52 -0400 Subject: [erlang-questions] pid to integer and back In-Reply-To: References: <48ECDAFE.5020205@alertlogic.net> Message-ID: <6a36e7290810080945o63924981h32e3ac9ffe8cfc2f@mail.gmail.com> It's probably a bad idea (though I guess not much worse than any other serialization of pids) but you could use pid_to_list and list_to_pid. If you want a more compact representation you could parse it. On Wed, Oct 8, 2008 at 12:13 PM, Joel Reymont wrote: > Paul, > > That's quite rich at 27 bytes. I would prefer 12 (4x3). > > Thanks, Joel > > On Oct 8, 2008, at 5:08 PM, Paul Fisher wrote: > >> Does it really need to be an integer? Can you do a fixed size >> binary (e.g. term_to_binary(pid()))? > > -- > wagerlabs.com > > > > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From vychodil.hynek Wed Oct 8 18:54:28 2008 From: vychodil.hynek (Hynek Vychodil) Date: Wed, 8 Oct 2008 18:54:28 +0200 Subject: [erlang-questions] pid to integer and back In-Reply-To: References: <20081008161406.6F7D12402F@relay.gooddata.com> Message-ID: <20081008165429.4237924012@relay.gooddata.com> Use term_to_binary and just remove starting 131, 130 and following node information, you take 9 bytes and use this. Or you can get only ID part which is only 4bytes. But you must experiment how assemble back and verify. On Wed, Oct 8, 2008 at 6:24 PM, Joel Reymont wrote: > I know you can put pids back together with c:pid(X, Y, Z). > > How do you take a triple apart, though, without using pid_to_list and > parsing the string? > > Thanks, Joel > > -- > wagerlabs.com > > > > > > -- --Hynek (Pichi) Vychodil -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081008/8177ab3b/attachment.html From hydo Wed Oct 8 17:01:00 2008 From: hydo (Clint Moore) Date: Wed, 08 Oct 2008 08:01:00 -0700 Subject: [erlang-questions] Parallel list proccessing once again Message-ID: <55E8C5F7-41B5-4BD5-8AF0-62BD4E1D5B3C@mac.com> Before I try to write it, I thought I would ask and see if there isn't already something that does this. What I want to do is connect up a bunch of nodes and throw arbitrary functions and data to them and get the responses back in an easily manageable way _without_ overloading the nodes. This module would take care of checking for smp support on the individual nodes to see if it can throw more than one block to it or not, take care of waiting for all of the responses, and resend any blocks that didn't come back. Yea, I know... it's not a small thing but it seems like it would be incredibly useful. The data set I'm working off of is ~28k twitter messages in the form of: [[ { service, "twitter" }, { user, "name" }, { update, "text"}, { updated, date }, ... ]] called Dx. Let's suppose I have a function that takes a list of words and checks for @some_word and, if it finds it, replacing it with @some_word which makes a clickable link to that user for some web-based twitter interface. We'll call this function Fx. Here's what I want to do: (node) 1> ResultSet = awesome_module:distributed_map( Fx, Dx ). ... (node) 2> I could have 100 or no other nodes connected, it wouldn't matter because the module would put as much load on a node as it could handle (A lagom number of processes, I believe?) based off of erlang:system_info(smp_support) or whatever else. Is there anything like this already or is my newbishness with Erlang making the problem sound much more than it actually is? From joelr1 Wed Oct 8 20:10:33 2008 From: joelr1 (Joel Reymont) Date: Wed, 8 Oct 2008 19:10:33 +0100 Subject: [erlang-questions] pid to integer and back In-Reply-To: <20081008165429.4EDD12402F@relay.gooddata.com> References: <20081008161406.6F7D12402F@relay.gooddata.com> <20081008165429.4EDD12402F@relay.gooddata.com> Message-ID: <09C01AA9-EA01-4CBE-AAC3-BF4054D4958A@gmail.com> On Oct 8, 2008, at 5:54 PM, Hynek Vychodil wrote: > Use term_to_binary and just remove starting 131, 130 and following > node > information, you take 9 bytes and use this. Or you can get only ID > part > which is only 4bytes. That would work. I have a question, though... Under what conditions can the serial portion of the PID change? That would be the Z in . Thanks, Joel -- wagerlabs.com From anders.nygren Wed Oct 8 20:21:39 2008 From: anders.nygren (Anders Nygren) Date: Wed, 8 Oct 2008 13:21:39 -0500 Subject: [erlang-questions] Parallel list proccessing once again In-Reply-To: <55E8C5F7-41B5-4BD5-8AF0-62BD4E1D5B3C@mac.com> References: <55E8C5F7-41B5-4BD5-8AF0-62BD4E1D5B3C@mac.com> Message-ID: On Wed, Oct 8, 2008 at 10:01 AM, Clint Moore wrote: > > Before I try to write it, I thought I would ask and see if there > isn't already something that does this. What I want to do is connect > up a bunch of nodes and throw arbitrary functions and data to them and > get the responses back in an easily manageable way _without_ > overloading the nodes. This module would take care of checking for > smp support on the individual nodes to see if it can throw more than > one block to it or not, take care of waiting for all of the responses, > and resend any blocks that didn't come back. > > Yea, I know... it's not a small thing but it seems like it would be > incredibly useful. The data set I'm working off of is ~28k twitter > messages in the form of: > > [[ { service, "twitter" }, { user, "name" }, { update, "text"}, > { updated, date }, ... ]] called Dx. > > Let's suppose I have a function that takes a list of words and checks > for @some_word and, if it finds it, replacing it with href="http://...">@some_word which makes a clickable link to that > user for some web-based twitter interface. We'll call this function Fx. > > Here's what I want to do: > > (node) 1> ResultSet = awesome_module:distributed_map( Fx, Dx ). > ... > (node) 2> > > I could have 100 or no other nodes connected, it wouldn't matter > because the module would put as much load on a node as it could handle > (A lagom number of processes, I believe?) based off of > erlang:system_info(smp_support) or whatever else. > > Is there anything like this already or is my newbishness with Erlang > making the problem sound much more than it actually is? > To start with take a look at the pool module in the stdlib. Another thing to consider is the cost of sending the data and the results between the nodes compared to the actual amount of work done. From Your description it sounds like the work done on each message is not very much. Sometimes it is better to have the data distributed and then just sending the functions for doing the work to where the data is. /Anders > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From torben.lehoff Wed Oct 8 21:04:50 2008 From: torben.lehoff (Torben Hoffmann) Date: Wed, 8 Oct 2008 21:04:50 +0200 Subject: [erlang-questions] pid to integer and back In-Reply-To: References: Message-ID: On Wed, Oct 8, 2008 at 6:01 PM, Joel Reymont wrote: > Is there a safe and efficient way to convert pid to integer and back? > > I'm assigning each running poker game an integer id. I store this id > into every outgoing packet so there's no database lookup. > > I use the id to lookup the game process for every incoming packet, > though. This is proving to be extremely inefficient, even with dirty > mnesia reads. > > I actually repeat the above for every player, so there's twice the > overhead. Is there a way to avoid it? > > This would only apply to running games and connected players so this > would be a temporary integer, valid while the process is alive. > > Thanks, Joel > > -- > wagerlabs.com > > Hi Joel. I haven't - shame on me - looked at your code for the poker server, so this may be a stupid question... Could you try to step one step back and explain a bit about the scenario and the requirements you have for the routing of messages. I presume that you have local clients that all connect to your server and the trick is to pass actions around to all players at a table, but how that matches up with Erlang entities is beyond me at this stage. Off the top of my head things like AMQP or IP multicast could be a neat way of solving your problem, but it depends on how your architecture is and exactly how your routing requirements are. I have practical experience with IP multicast and I am sure that the RabbitMQ guys could help out with guidance on using AMQP.... if those things match your needs. It might very well be that the pid conversion is a problem you do not need to solve! Cheers, Torben > _____________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081008/4eca80bd/attachment.html From joelr1 Wed Oct 8 21:15:37 2008 From: joelr1 (Joel Reymont) Date: Wed, 8 Oct 2008 20:15:37 +0100 Subject: [erlang-questions] pid to integer and back In-Reply-To: References: Message-ID: <940411B6-1443-45EC-AF37-BB0ADFEAEBD6@gmail.com> On Oct 8, 2008, at 8:04 PM, Torben Hoffmann wrote: > Could you try to step one step back and explain a bit about the > scenario and the requirements you have for the routing of messages. Players connect to a gateway which tells them the server to connect to. Once connected, they can request the list of games running. This is a list of _all_ games running across the poker cluster. Once players have the game summary, they can request the details, e.g. what seats are occupied, etc. I know the id and thus the pid of each player since everything from the client side goes to a matching player process. The issue is that messages are routed to a game by the player process and so the game id in the packet needs to be converted to a pid. I'll go with term_to_binary for now and trade packet size for speed. -- wagerlabs.com From torben.lehoff Wed Oct 8 21:48:35 2008 From: torben.lehoff (Torben Hoffmann) Date: Wed, 8 Oct 2008 21:48:35 +0200 Subject: [erlang-questions] pid to integer and back In-Reply-To: <940411B6-1443-45EC-AF37-BB0ADFEAEBD6@gmail.com> References: <940411B6-1443-45EC-AF37-BB0ADFEAEBD6@gmail.com> Message-ID: On Wed, Oct 8, 2008 at 9:15 PM, Joel Reymont wrote: > > On Oct 8, 2008, at 8:04 PM, Torben Hoffmann wrote: > > Could you try to step one step back and explain a bit about the scenario >> and the requirements you have for the routing of messages. >> > > Players connect to a gateway which tells them the server to connect to. > > Once connected, they can request the list of games running. This is a list > of _all_ games running across the poker cluster. > > Once players have the game summary, they can request the details, e.g. what > seats are occupied, etc. > > I know the id and thus the pid of each player since everything from the > client side goes to a matching player process. The issue is that messages > are routed to a game by the player process and so the game id in the packet > needs to be converted to a pid. For this I am almost 100% sure that IP multicast routing would work - the question is if IP multicast is allowed across the internet; I cannot read this from the entry about it in Wikipedia. The basic set-up would be to associate a multicast address with each game and then all that joins the multicast group will receive the messages sent on that address. You could let the gateway manage the multicast address pool and when a player wants to get a list of all games running you return the list of active multicast groups. Then the player can query the games for details... hmmm, this could lead to a lot of noise so it might be necessary to create a "control" layer that deals with queries and such and only use the multicast addresses for the in-game related messages which do need to go to every player at the table. AMQP would support this as well, but I am not an expert on that protocol. It is based on TCP so there will be no problems with running it over the internet. Another question: once a player has joined a table in your implementation couldn't he store the pid for the game once and for all and then route all messages to the game using the stored pid? Cheers, Torben -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081008/9f4238ce/attachment.html From dbudworth Wed Oct 8 22:45:48 2008 From: dbudworth (David Budworth) Date: Wed, 8 Oct 2008 15:45:48 -0500 Subject: [erlang-questions] pid to integer and back In-Reply-To: References: <940411B6-1443-45EC-AF37-BB0ADFEAEBD6@gmail.com> Message-ID: <2e23d1d20810081345o3e1dcef1i35d41de410997152@mail.gmail.com> The whole point of the poker server is to enable web based poker contests / gambling / etc, right? if that's true, i think you can't afford to allow guessable game id's. what stops someone from just sending in packets to all the games? since you are using an int (or even erlang pids as binaries) you basically are using sequential numbers for game identifiers. for something where money is at stake, or even in a contest with prizes of some form. The temptation to hack or even just disrupt will be high. or is this a closed network system where clients are controlled? 2008/10/8 Torben Hoffmann > > > On Wed, Oct 8, 2008 at 9:15 PM, Joel Reymont wrote: > >> >> On Oct 8, 2008, at 8:04 PM, Torben Hoffmann wrote: >> >> Could you try to step one step back and explain a bit about the scenario >>> and the requirements you have for the routing of messages. >>> >> >> Players connect to a gateway which tells them the server to connect to. >> >> Once connected, they can request the list of games running. This is a list >> of _all_ games running across the poker cluster. >> >> Once players have the game summary, they can request the details, e.g. >> what seats are occupied, etc. >> >> I know the id and thus the pid of each player since everything from the >> client side goes to a matching player process. The issue is that messages >> are routed to a game by the player process and so the game id in the packet >> needs to be converted to a pid. > > > For this I am almost 100% sure that IP multicast routing would work - the > question is if IP multicast is allowed across the internet; I cannot read > this from the entry about it in Wikipedia. The basic set-up would be to > associate a multicast address with each game and then all that joins the > multicast group will receive the messages sent on that address. You could > let the gateway manage the multicast address pool and when a player wants to > get a list of all games running you return the list of active multicast > groups. Then the player can query the games for details... hmmm, this could > lead to a lot of noise so it might be necessary to create a "control" layer > that deals with queries and such and only use the multicast addresses for > the in-game related messages which do need to go to every player at the > table. > > AMQP would support this as well, but I am not an expert on that protocol. > It is based on TCP so there will be no problems with running it over the > internet. > > Another question: once a player has joined a table in your implementation > couldn't he store the pid for the game once and for all and then route all > messages to the game using the stored pid? > > Cheers, > Torben > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081008/14826d13/attachment.html From joelr1 Wed Oct 8 23:34:13 2008 From: joelr1 (Joel Reymont) Date: Wed, 8 Oct 2008 22:34:13 +0100 Subject: [erlang-questions] pid to integer and back In-Reply-To: References: <940411B6-1443-45EC-AF37-BB0ADFEAEBD6@gmail.com> Message-ID: On Oct 8, 2008, at 8:48 PM, Torben Hoffmann wrote: > For this I am almost 100% sure that IP multicast routing would work > - the question is if IP multicast is allowed across the internet; I had a lot of trouble with multicast and my Cisco router, I don't think I want to be concerned with multicast, at least not now. > Another question: once a player has joined a table in your > implementation > couldn't he store the pid for the game once and for all and then > route all messages to the game using the stored pid? This is not a problem but it won't work when you need to join a game. I still need to either map integers to process ids or use term_to_binary. -- wagerlabs.com From joelr1 Wed Oct 8 23:35:48 2008 From: joelr1 (Joel Reymont) Date: Wed, 8 Oct 2008 22:35:48 +0100 Subject: [erlang-questions] pid to integer and back In-Reply-To: <2e23d1d20810081345o3e1dcef1i35d41de410997152@mail.gmail.com> References: <940411B6-1443-45EC-AF37-BB0ADFEAEBD6@gmail.com> <2e23d1d20810081345o3e1dcef1i35d41de410997152@mail.gmail.com> Message-ID: <5307195D-F66D-4883-B1A3-19F101439CE8@gmail.com> On Oct 8, 2008, at 9:45 PM, David Budworth wrote: > The whole point of the poker server is to enable web based poker > contests / > gambling / etc, right? Right. > if that's true, i think you can't afford to allow guessable game id's. > what stops someone from just sending in packets to all the games? You can't do that. You can only send certain packets when you are not playing the game and other packets when you are. A game won't accept packets from you unless you are playing, etc. > for something where money is at stake, or even in a contest with > prizes of some form. The temptation to hack or even just disrupt > will be high. I think I can deal with it. > or is this a closed network system where clients are controlled? This is not the case. You can write a client if you want to. -- wagerlabs.com From b88zhou Wed Oct 8 23:38:56 2008 From: b88zhou (Brian Zhou) Date: Wed, 8 Oct 2008 14:38:56 -0700 Subject: [erlang-questions] Problems cross-compiling OTP on ARM In-Reply-To: References: <48DCC42D.70302@diit.unict.it> <48E0F984.8040206@diit.unict.it> Message-ID: <859e91e70810081438w1fb2f98dw18b5e10bad3c1a2a@mail.gmail.com> Sorry I join this topic late. For anyone interested in cross compiling erlang, please see also http://trac.nslu2-linux.org/optware/browser/trunk/make/erlang.mk http://trac.nslu2-linux.org/optware/browser/trunk/sources/erlang I've been maintaining the cross compilation recipes for NAS devices for a while. Some of the patches can probably go upstream. -Brian Zhou bzhou at nslu2 dash linux dot org From b88zhou Wed Oct 8 23:56:34 2008 From: b88zhou (Brian Zhou) Date: Wed, 8 Oct 2008 14:56:34 -0700 Subject: [erlang-questions] write the ant simulation in Erlang? Message-ID: <859e91e70810081456w244b1c9dh74e108325ae4135c@mail.gmail.com> Recently I watched clojure concurrency video, very impressive talk. http://blip.tv/file/812787 In the talk, lot of time was spent on walking thru the ant simulation code. Like many of you here, I was not convinced by the STM approach. Especially seeing the "Santa Claus" solution in Haskell and Erlang side-by-side. But I'm having some difficulty thinking about how to use Erlang for this ant simulation problem. It was suggested to me in IRC to have a manager process for the world state, with interface like world:is_food(loc). But how to make sure certain calls are in a a transaction? e.g. world:is_food(loc) and world:take_food(loc)? Maybe move what needs to be in a transaction into world:single_function() ? Thanks in advance for any idea, -Brian From b88zhou Thu Oct 9 00:29:07 2008 From: b88zhou (Brian Zhou) Date: Wed, 8 Oct 2008 15:29:07 -0700 Subject: [erlang-questions] write the ant simulation in Erlang? In-Reply-To: <859e91e70810081456w244b1c9dh74e108325ae4135c@mail.gmail.com> References: <859e91e70810081456w244b1c9dh74e108325ae4135c@mail.gmail.com> Message-ID: <859e91e70810081529w4c2245d5rfe0f069772941e7d@mail.gmail.com> The informal condensed description of the problem starts at ~76:00 of the video. You can see the simulation in action at 131:00 - 132:00. -Brian On Wed, Oct 8, 2008 at 2:56 PM, Brian Zhou wrote: > Recently I watched clojure concurrency video, very impressive talk. > > http://blip.tv/file/812787 > > In the talk, lot of time was spent on walking thru the ant simulation code. > > Like many of you here, I was not convinced by the STM approach. > Especially seeing the "Santa Claus" solution in Haskell and Erlang > side-by-side. > > But I'm having some difficulty thinking about how to use Erlang for > this ant simulation problem. > > It was suggested to me in IRC to have a manager process for the world > state, with interface like world:is_food(loc). But how to make sure > certain calls are in a a transaction? e.g. world:is_food(loc) and > world:take_food(loc)? Maybe move what needs to be in a transaction > into world:single_function() ? > > Thanks in advance for any idea, > > -Brian > From matthew Thu Oct 9 00:41:19 2008 From: matthew (Matthew Dempsky) Date: Wed, 8 Oct 2008 15:41:19 -0700 Subject: [erlang-questions] pid to integer and back In-Reply-To: References: <940411B6-1443-45EC-AF37-BB0ADFEAEBD6@gmail.com> Message-ID: 2008/10/8 Torben Hoffmann : > For this I am almost 100% sure that IP multicast routing would work - the > question is if IP multicast is allowed across the internet; You would probably setup a VPN connecting all of your sites and then run multicast over that. From rvirding Thu Oct 9 01:01:57 2008 From: rvirding (Robert Virding) Date: Thu, 9 Oct 2008 01:01:57 +0200 Subject: [erlang-questions] extending the scanner and parser In-Reply-To: References: <95be1d3b0810030413p52bc5b58uf22c6790d64f9f35@mail.gmail.com> <20081003151527.GA28655@myrtle.kent.ac.uk> <95be1d3b0810031126t5fb7b8b9x48bb75c3895a330e@mail.gmail.com> <3dbc6d1c0810041115p571160fft458be1a867ff6cf2@mail.gmail.com> <95be1d3b0810041127o3d733f09l5182c0499ee57daa@mail.gmail.com> Message-ID: <3dbc6d1c0810081601t3832e4e1s47af36a31ef635ad@mail.gmail.com> 2008/10/6 Kenneth Lundin > On Sat, Oct 4, 2008 at 8:27 PM, Vlad Dumitrescu > wrote: > > On Sat, Oct 4, 2008 at 20:15, Robert Virding wrote: > >> Another solution which may help you is to use leex for generating the > >> scanner. > As I said we plan to integrate the required functionality in the > official scanner and we can not > have dependencies to components which are not part of the distribution > in the scanner. > We also already have the scanner so there is really no need to > implement a new one with Leex. Yes, but there is a BIG difference between modifying the output when using leex and going in and hacking the erlang scanner. With leex is is easy to see what you generate. However it is probably more difficult to make leex save more information and make it available to the user, or perhaps not. As far as I know there is only one thing which leex cannot handle today in the erlang syntax and that is that leex needs a newline at the end of the file, the erlang scanner does not. Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/9814fa7f/attachment.html From erlang-questions_efine Thu Oct 9 01:42:25 2008 From: erlang-questions_efine (Edwin Fine) Date: Wed, 8 Oct 2008 19:42:25 -0400 Subject: [erlang-questions] [enhancement] string:split/2 Message-ID: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> Splitting a string into multiple parts based on a literal (as opposed to regular expression or set of characters) string delimiter is an extremely common operation in text processing. Its equal and opposite partner, join, is also very common. split and join are complementary functions (that's just what I call them here, so even if there's some more accurate or widely used terminology, please bear with me). At present, string:join exists and behaves like its cousins in other programming languages. There is an *almost*, but not quite complementary function in the string module: string:tokens/2. It *should* be possible to perform an idempotent transformation as follows: Input = "A,,B,C,", Sep = ",", Output = string:join(string:tokens(Input, Sep), Sep), Output =:= Input. The above would return *true* if string:join and string:tokens were truly complementary, but it does not. However, there is nothing *wrong* with string:tokens as it stands today (except maybe that it's a bit underdocumented, for example, by not mentioning that it treats consecutive sequences of delimiters as a single delimiter). It does what its name suggests: tokenizes a string based on a set of token characters. In a tokenization operation, you usually *want* to skip multiple identical token delimiters, and that's precisely what it does. I am not proposing a change to string:tokens; I *am* proposing *the addition of string:split/2*. split(String, Separator) -> List Types: String = string() Separator = string() List = [string()] Returns a list of strings that were separated in String by Separator. Separator can contain any number of characters, including zero. Leading separators will result in empty strings as the first elements of the returned list; the same is true for trailing separators and multiple consecutive separators. If Separator is the empty string, the returned list will be identical to the list returned by [[X] || X <- String]. If Separator cannot be found in String, the returned list will be [String]. In general, if there are N separators embedded in String, the returned list will contain N+1 strings. Examples: > string:split(":", ":This:is::a:contrived:example::"). ["","This","is","","a","contrived","example","",""] > string:split("", "Hello"). ["H","e","l","l","o"] *Existing Alternatives* There are no existing alternatives that I could find that have similar syntactic, semantic, and performance characteristics to split. Anything using regular expressions is more cumbersome and probably slower, and simulating this using Erlang code would also present performance penalties. I searched the list archives using the phrases "string split" and string:split, but found nothing that would cause me not to submit this proposal. EEP 9 does mention a binary_string:split, but I still feel that string:split would be a worthwhile addition to balance string:join. I believe this is too trivial an addition to warrant an EEP, so I am proposing it to the list for comment. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081008/ade2c1c8/attachment.html From ok Thu Oct 9 03:33:42 2008 From: ok (Richard O'Keefe) Date: Thu, 9 Oct 2008 14:33:42 +1300 Subject: [erlang-questions] ?DATE and ?TIME MACROs In-Reply-To: <48EB2D4D.2060909@gmail.com> References: <48EB2D4D.2060909@gmail.com> Message-ID: <81D9E81B-D137-4377-AB2B-C082B9F3FA30@cs.otago.ac.nz> On 7 Oct 2008, at 10:35 pm, Mats Cronqvist wrote: > > -define(DATE,proplists:get_value(time,?MODULE:module_info(compile))). Just in case it's not obvious, it may be worth pointing out the ?DATE and ?TIME implemented this way, and the ?FUNCTION macro that has previously been posted, - do not give you ground terms, so the new-in-R12 optimisation of storing ground terms once won't happen - are not usable in patterns. The second of these may not matter to many people, but the first is at least potentially a space issue for people wanting to use such macros heavily in logging/debugging code. From ok Thu Oct 9 04:13:23 2008 From: ok (Richard O'Keefe) Date: Thu, 9 Oct 2008 15:13:23 +1300 Subject: [erlang-questions] re cursive fun() In-Reply-To: <20081007113238.85D1624083@relay.gooddata.com> References: <19820386.post@talk.nabble.com> <48E8892E.5040204@it.uu.se> <8e04b5820810050711s5d4ef554v50131c481fa19e85@mail.gmail.com> <58B11B10-F2AA-4702-A625-A73F9F239A40@cs.otago.ac.nz> <20081007113238.85D1624083@relay.gooddata.com> Message-ID: <940285B1-4CCE-4E67-AD87-F369B7082F5B@cs.otago.ac.nz> On 8 Oct 2008, at 12:32 am, Hynek Vychodil wrote: > Is there any problem write this think this way? > > F = begin > Outher = fun(OSelf, ...) -> > ... > Inner = fun(ISelf, ....) -> > ... ISelf(ISelf, X) ... > ... OSelf(OSelf, Y) ... > end, > ... OSelf(OSelf, ...) ... Inner(Inner, ...) ... > fun(Args) -> Outher(Outher, Args) end > end. Given that the topic under discussion was syntactic support to enable the *direct* representation of recursive functions, yes. I agree that we *can* get the effect right now without any extensions at all to the language. The result can most charitably be described as unclear and error-prone. Really, if you want a recursive function, there is no better way to write it than as a plain ordinary Erlang function. As for writing functions in the shell, it is so easy to have an editor in another window letting you write and edit any number of functions and then just using c(...) in the shell that there doesn't seem to be any real point in trying to write non-trivial functions in the shell. By the way, my understanding is that "begin" and "end" in Erlang are, as a pair, precisely equivalent to "(" and ")". > For Example factorial: > > Fact = begin F = fun(_, 0) -> 1; (Self, N) -> Self(Self, N-1)*N end, > fun(N) -> F(F, N) end end. A couple of days ago a 56-year-old member of this university was killed in a tramping accident. She and her teenage daughter were tramping in one of the national parks in the North Island, which has been having some heavy weather recently. Apparently the park people warned her of the the effect the weather had been having on the rivers, and told her of an alternative, safer, route. The route this experienced tramper chose involved a river crossing. The river was swollen with the rain, and swept her away. Her daughter immediately called for help on a mobile phone, but it was already too late. What has this to do with programming in Erlang? This: PEOPLE MAKE MISTAKES ALL THE TIME. When you've made a mistake, you need TIME to notice and recover. If you've typed something in an editor window, you have *time* to look at it, to check it, to think "maybe this could do a bit more checking". And if you get it wrong, you have it there to fix. But if you type something in the shell, you are under subtle pressure to do it quickly and briefly. Note, for example, the difference in how Hynek Vychodil's two examples were laid out. I'm sure that in an edit window he would write something _at least_ as good as factorial(N) when N > 0 -> N * factorial(N-1); factorial(0) -> 1. > Some nontrivial example: > > 4> UpToGen = begin > Outher = fun(_OSelf, M, M) -> []; > (OSelf, Step, M) -> > Inner = fun(_ISelf, N) when N>M > -> []; > (ISelf, N) -> [N > | ISelf(ISelf, N+Step) ] > end, > [Inner(Inner, 0) | OSelf(OSelf, Step > +1, M)] > end, > fun(Max) -> Outher(Outher, 1, Max) end > end. This must have been done with tabs set to something other than the standard 8. The problem is that I cannot tell what it is supposed to do without far more work than I have time for right now. What I *can* say is that it looks like a textbook example of something that should not have been written that way. > > #Fun > 5> UpToGen(10). > [[0,1,2,3,4,5,6,7,8,9,10], > [0,2,4,6,8,10], > [0,3,6,9], > [0,4,8], > [0,5,10], > [0,6], > [0,7], > [0,8], > [0,9]] To get this particular result, one does [lists:seq(0, 10, Step) || Step <- lists:seq(1, 9)] at to get the general version, U = fun (N) -> [lists:seq(0, N, Step) || Step <- lists:seq(1, N-1)] end will do fine. Even factorial can be done as F = fun (N) -> lists:foldl(fun (X, Y) -> X * Y end, 1, lists:seq(1, N)) end. Or rather, this *WOULD* work if it weren't for the lists:seq(1, 0) bug that I have complained about before. Similarly, U(1) *ought* to be the empty list, but thanks to the lists:seq(1, 0) but it crashes. People, it really is time to fix that bug. From ok Thu Oct 9 04:28:07 2008 From: ok (Richard O'Keefe) Date: Thu, 9 Oct 2008 15:28:07 +1300 Subject: [erlang-questions] ?DATE and ?TIME MACROs In-Reply-To: <48EC562F.7060408@it.uu.se> References: <48EC562F.7060408@it.uu.se> Message-ID: <7DF2C733-5DF0-451C-860F-382876E3C6F5@cs.otago.ac.nz> On 8 Oct 2008, at 7:41 pm, Richard Carlsson wrote: > FUNCTION, however, does not really belong in the preprocessor, because > it can never be expanded at preprocessing time to a literal (so that > you > can e.g. use it in a pattern); it must expand to a runtime call It can't be expanded at preprocessing time to a literal, true. But it CAN be expanded at preprocessing time to a {location,Line_Number,function} token which the *parser* can expand to a literal (so that you can for example use it in a pattern). (Actually, with a bit more work, the preprocessor *could* do that part as well, but this would mean repeating work already done by the parser, so I wouldn't do it that way.) From ok Thu Oct 9 05:51:52 2008 From: ok (Richard O'Keefe) Date: Thu, 9 Oct 2008 16:51:52 +1300 Subject: [erlang-questions] [enhancement] string:split/2 In-Reply-To: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> Message-ID: I agree that there should be an operation that is the converse of string:join/2. I'd like to see the spelling mistake (s/Seperators/Separators/) fixed in the comment for string:tokens/2. Can anyone explain to me why -spec(tokens/2 :: (string(), string()) -> [[char(),...]]). doesn't mention "string()" on the right hand side of the arrow? There are three minor quibbles about the proposed string:split/2. (1) We already have lists:split/2 and lists:splitwith/2. A module system exists so that names can safely be reused, but this is a little too close for comfort. While 'unjoin' is uglier than 'split', maybe it would mean less confusion? (2) What should string:split(Input, "") do? One plausible answer would be to split the input into a list of single-character strings. I know this is what Edwin Fine asked for, but is it the _right_ thing to do? Why is "abc" "" -> ["a","b","c"] the right answer rather than ["abc"], for example? Why is the separator deemed to occur only between characters and not at the beginning or end, yielding ["","a","b","c",""]? Perhaps the best answer for now is to require the separator to be a non-empty list. (3) unjoin:unjoin(";;;abc;;de;f;g;;", ";;"). [[],";abc","de;f;g",[]] Is that the right answer, or should it be [";","abc","de;f;g",[]]? > It should be possible to perform an idempotent transformation as > follows: An idempotent transformation F is one such that F(F(X)) = F(X) I see no idempotent transformation here. A useful operation, yes, but an idempotent one, no. > Examples: > > > string:split(":", ":This:is::a:contrived:example::"). > ["","This","is","","a","contrived","example","",""] > > string:split("", "Hello"). > ["H","e","l","l","o"] > Since the separator is the SECOND argument of string:join/2, I suggest that it should be the SECOND argument of string:unjoin/2 as well. The following code (1) has the name I suggested (unjoin/2) rather than the name Edwin Fine suggested (split/2); (2) has the argument order I suggested (consistent with join/2) rather than the argument order Edwin Fine suggested; (3) has the "split into single character strings" behaviour when presented with an empty separator that Edwin Fine suggested, rather than any of the alternatives I did; (4) has been tested. unjoin(String, []) -> unjoin0(String); unjoin(String, [Sep]) when is_integer(Sep) -> unjoin1(String, Sep); unjoin(String, [C1,C2|L]) when is_integer(C1), is_integer(C2) -> unjoin2(String, C1, C2, L). %% Split a string at "", which is deemed to occur _between_ %% adjacent characters, but queerly, not at the beginning %% or the end. unjoin0([C|Cs]) -> [[C] | unjoin0(Cs)]; unjoin0([]) -> []. %% Split a string at a single character separator. unjoin1(String, Sep) -> unjoin1_loop(String, Sep, ""). unjoin1_loop([Sep|String], Sep, Rev) -> [lists:reverse(Rev) | unjoin1(String, Sep)]; unjoin1_loop([Chr|String], Sep, Rev) -> unjoin1_loop(String, Sep, [Chr|Rev]); unjoin1_loop([], _, Rev) -> [lists:reverse(Rev)]. %% Split a string at a multi-character separator %% [C1,C2|L]. These components are split out for %% a fast match. unjoin2(String, C1, C2, L) -> unjoin2_loop(String, C1, C2, L, ""). unjoin2_loop([C1|S = [C2|String]], C1, C2, L, Rev) -> case unjoin_prefix(L, String) of no -> unjoin2_loop(S, C1, C2, L, [C1|Rev]) ; Rest -> [lists:reverse(Rev) | unjoin2(Rest, C1, C2, L)] end; unjoin2_loop([Chr|String], C1, C2, L, Rev) -> unjoin2_loop(String, C1, C2, L, [Chr|Rev]); unjoin2_loop([], _, _, _, Rev) -> [lists:reverse(Rev)]. unjoin_prefix([C|L], [C|S]) -> unjoin_prefix(L, S); unjoin_prefix([], S) -> S; unjoin_prefix(_, _) -> no. From saleyn Thu Oct 9 05:58:26 2008 From: saleyn (Serge Aleynikov) Date: Wed, 08 Oct 2008 23:58:26 -0400 Subject: [erlang-questions] jinterface In-Reply-To: <3dbc6d1c0810080657u4891111cr2052dc90488290f8@mail.gmail.com> References: <6C2A5378-5BDE-4FF9-B2AF-790D1F78330B@kallisys.net> <48E7730B.3090506@gmail.com> <3dbc6d1c0810040711w26eae030pbcbccf7e1f4d5fd0@mail.gmail.com> <48E78277.4000809@gmail.com> <3dbc6d1c0810040757u795d521ex4223ad37a4ab3900@mail.gmail.com> <48ECA96B.2030201@gmail.com> <3dbc6d1c0810080657u4891111cr2052dc90488290f8@mail.gmail.com> Message-ID: <48ED8162.4050405@gmail.com> Robert Virding wrote: > Yes, it is easy to get around this, but no it is not. The io module was > designed to send the formatting computations to the io-server to be done > there. The group leader is an io-server as well as being group leader (see > my Erlang Rationale for a bit better explanation). As I see it you have the > following options: > > - Do not use io:fwrite or other formatting io calls directly but instead do > io:put_chars(io_lib:fwrite(Fmt, Args)) instead. This ensures that only an > iolist is sent to the group leader. This would be quite limiting as I cannot control nested functions (that may have io calls) that are being called by functions executed via RPC. > - Modify io.erl to do this for automatically for you and use this private > version. This is not difficult and should cause no other problems. I think this is the most convenient option out of the three. What was the rationale of having the io server do the formatting as opposed to the node generating the io output request? Was it to decrease the possible load on the evaluating node? > - Modify your program so that you start a local group leader/io-server which > does the formatting and just send the output iolists to the otp.net process. The otp.net node already has a mailbox for getting messages destined to the io_server, and rpc requests carry the pid of that mailbox. Ideally I wouldn't need to have another "proxy" io_server on the Erlang side that would format and send requests to the connected otp.net hidden node. > Do you do any input from otp.net? What I did as far as the input was concerned - I wrote a parser of Erlang terms that took a string (such as "M:F(Arg1, Arg2, ...)" from the otp.net's stdin or a UI text box, converted it to an AST corresponding to a valid Erlang term in external term format, and did an RPC call to a connected Erlang node. Though, the purpose of this exercise was not to compete with werl, but rather offer RPC (and optional shell-like capabilities) to a rich UI client interface. Serge From ok Thu Oct 9 06:37:11 2008 From: ok (Richard O'Keefe) Date: Thu, 9 Oct 2008 17:37:11 +1300 Subject: [erlang-questions] [enhancement] string:split/2 In-Reply-To: References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> Message-ID: <34A27838-5CBA-425D-97A1-C2D2CF6F5456@cs.otago.ac.nz> Colour me stupid. I just realised, 40+ minute late, what Fine meant about "idempotent" and why it matters. The requirement is that for all strings String and Separator for all Substring <- unjoin(String, Separator) unjoin(Substring, Separator) =:= [Substring] This _isn't_ idempotence, but it's some sort of cousin to it. And this is why unjoin("abc", "") doesn't include empty matches at the beginning and end, so that unjoin("a", "") =:= ["a"]. From b88zhou Thu Oct 9 06:46:29 2008 From: b88zhou (Brian Zhou) Date: Wed, 8 Oct 2008 21:46:29 -0700 Subject: [erlang-questions] write the ant simulation in Erlang? In-Reply-To: <859e91e70810082144v52c0998bi140a6116c67cf12a@mail.gmail.com> References: <859e91e70810081456w244b1c9dh74e108325ae4135c@mail.gmail.com> <7D2420AE-BA6D-4EE4-85DD-CCB6C1723DBE@cs.otago.ac.nz> <859e91e70810082144v52c0998bi140a6116c67cf12a@mail.gmail.com> Message-ID: <859e91e70810082146k3457bd2evc813a51beda59989@mail.gmail.com> Let me try to reverse engineer some kind of spec: * On a world of 80x80 cells, there are 49 ants, and 35 scattered cells with food. * Initially the ants are in their home, a square from (20, 20) to (26, 26), facing random directions. * An ant can move ahead, turn 45 degree left, or 45 degree right, every 40ms. * Ant should not move ahead if there is another ant in the ahead cell. * Whenever ant make a move, it leaves a pheromone trail by increment pheromone amount by 1.0 in the previous cell. * For an ant without food, ** If ahead is not home, and there is food ahead, move ahead, take food and turn around; ** Among cells that are ahead, ahead-left (45 degree), ahead-right (45 degree), turn/move to the one with the most (if (contain-food?) 1 0) + pheromone score, if all equal, turn/move randomly; * For an ant with food, ** If ahead is home, move ahead, drop food and turn around; ** Among cells that are ahead, ahead-left (45 degree), ahead-right (45 degree), turn/move to the one with the most (if (at-home?) 1 0) + pheromone score, if all equal, turn/move randomly; * Every 1 second, the pheromone in all cells evaporate to 99% of the previous amount; * If a graphical animation is provided, the animation is refreshed every 100ms. * Hard-coded numbers are used above to make description easier. They are actually adjustable. ;dimensions of square world (def dim 80) ;number of ants = nants-sqrt^2 (def nants-sqrt 7) ;number of places with food (def food-places 35) ;range of amount of food at a place (def food-range 100) ;evaporation rate (def evap-rate 0.99) (def animation-sleep-ms 100) (def ant-sleep-ms 40) (def evap-sleep-ms 1000) Anyone feel free to correct me if my understanding is not right. -Brian On Wed, Oct 8, 2008 at 7:46 PM, Richard O'Keefe wrote: > Bearing in mind that it really isn't practical > for someone in NZ to watch videos over the international net, > can you tell me what the ant simulation problem is? > > From romain.lenglet Thu Oct 9 07:18:50 2008 From: romain.lenglet (Romain Lenglet) Date: Thu, 09 Oct 2008 14:18:50 +0900 Subject: [erlang-questions] Article on Erlang in ACM Queue Message-ID: <48ED943A.80801@berabera.info> Jim Larson has written an article entitled "Erlang for Concurrent Programming", published in the latest ACM Queue: http://mags.acm.org/queue/200809/ This article is a very good, practical introduction to Erlang and OTP. -- Romain Lenglet From jim Thu Oct 9 08:00:20 2008 From: jim (Jim Larson) Date: Wed, 08 Oct 2008 23:00:20 -0700 Subject: [erlang-questions] Article on Erlang in ACM Queue In-Reply-To: Your message of "Thu, 09 Oct 2008 14:18:50 +0900." <48ED943A.80801@berabera.info> Message-ID: <200810090600.m9960KTF054979@krumkake.jetcafe.org> In message <48ED943A.80801> you write: >Jim Larson has written an article entitled "Erlang for Concurrent >Programming", published in the latest ACM Queue: >http://mags.acm.org/queue/200809/ Thanks to Romain for some great feedback on an early draft! Jim From erlang-questions_efine Thu Oct 9 08:43:36 2008 From: erlang-questions_efine (Edwin Fine) Date: Thu, 9 Oct 2008 02:43:36 -0400 Subject: [erlang-questions] [enhancement] string:split/2 In-Reply-To: References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> Message-ID: <6c2563b20810082343j255330ccp396cf4f8da0d2fe4@mail.gmail.com> On Wed, Oct 8, 2008 at 11:51 PM, Richard O'Keefe wrote: > I agree that there should be an operation that is > the converse of string:join/2. *That's* the word I wanted, thanks. > I'd like to see the spelling mistake (s/Seperators/Separators/) > fixed in the comment for string:tokens/2. > Can anyone explain to me why > > -spec(tokens/2 :: (string(), string()) -> [[char(),...]]). > > doesn't mention "string()" on the right hand side of the arrow? > > There are three minor quibbles about the proposed > string:split/2. > > (1) We already have lists:split/2 and lists:splitwith/2. > A module system exists so that names can safely be reused, > but this is a little too close for comfort. > Well, split is used in some very widespread languages like Perl, Ruby, and JavaScript. The version I proposed works much like Ruby's but doesn't have all the "kitchen sink" options that are available in Ruby. This being a multi-lingual software world, I decided to go with the Principle of Least Astonishment and do as the Romans do, as it were. I regret the much earlier naming of lists:split, which is a totally different beast, but I maintain that string:split is the right name. As long as people don't overuse import (which I never use, ever) it should be ok. If you *really* wanted to be perverse, you could call it nioj (only joking, I never understood the attraction of that Algol-68 esac/fi/od stuff). > > While 'unjoin' is uglier than 'split', maybe it would mean > less confusion? > Maybe. Yuk. > > (2) What should string:split(Input, "") do? > > One plausible answer would be to split the input into a > list of single-character strings. I know this is what > Edwin Fine asked for, but is it the _right_ thing to do? It's what Ruby and JavaScript do, and for all I know, others. That doesn't mean it's *right* but it does mean it's unsurprising for people who have to work across multiple languages that include these and similar ones. > Why is "abc" "" -> ["a","b","c"] the right answer rather > than ["abc"], for example? Why is the separator deemed > to occur only between characters and not at the beginning > or end, yielding ["","a","b","c",""]? > Good point. I suppose by convention, really; we are talking about an invisible zero-length string, after all, and there could be an infinite number of them in any string. I think. I am sure you can tell from my "idempotent" gaffe that I'm not a computer scientist by training; I are an enjineer. Perhaps the best answer for now is to require the separator > to be a non-empty list. > That would work... but could cause exceptions in places where it's not really an obvious error. I know you hate those. Me too. > (3) unjoin:unjoin(";;;abc;;de;f;g;;", ";;"). > [[],";abc","de;f;g",[]] > > Is that the right answer, or should it be > [";","abc","de;f;g",[]]? > Out of interest, what does Ruby do? irb(main):001:0> ";;;abc;;de;f;g;;".split ";;" => ["", ";abc", "de;f;g"] Neither of the above. Hmmm.. why? Ah. "If the *limit* parameter is omitted, trailing null fields are suppressed." (http://www.ruby-doc.org/core/classes/String.html#M000818) Well. Things *can* get really confusing. > It should be possible to perform an idempotent transformation as follows: >> > > An idempotent transformation F is one such that > > F(F(X)) = F(X) > > I see no idempotent transformation here. A useful operation, > yes, but an idempotent one, no. > I know, I know. I was trying to find the right word to signify a "round-trip" operation that leaves the operand unchanged, and was in too much of a hurry to make sure that idempotent meant that. Sorry. This is more of a sort of mutual identity operation, like f(g(x)) = x. > Examples: > > > string:split(":", ":This:is::a:contrived:example::"). > ["","This","is","","a","contrived","example","",""] > > string:split("", "Hello"). > ["H","e","l","l","o"] > > Since the separator is the SECOND argument of > string:join/2, I suggest that it should be the SECOND > argument of string:unjoin/2 as well. > That was very careless of me. I specially wrote the specification of string:split to be patterned after string:join, and then screwed up the example. Eheu, mea culpa (no, really, I could kick myself). > The following code > (1) has the name I suggested (unjoin/2) rather than the name > Edwin Fine suggested (split/2); > (2) has the argument order I suggested (consistent with join/2) > rather than the argument order Edwin Fine suggested; > (3) has the "split into single character strings" behaviour > when presented with an empty separator that Edwin Fine > suggested, rather than any of the alternatives I did; > (4) has been tested. > I'm assuming you are providing this code as an "executable requirements document." I was rather hoping that it could be implemented as a BIF. I'll have to study your code below so I can learn some "fast and fancy" Erlang! > unjoin(String, []) -> > unjoin0(String); > unjoin(String, [Sep]) when is_integer(Sep) -> > unjoin1(String, Sep); > unjoin(String, [C1,C2|L]) when is_integer(C1), is_integer(C2) -> > unjoin2(String, C1, C2, L). > > %% Split a string at "", which is deemed to occur _between_ > %% adjacent characters, but queerly, not at the beginning > %% or the end. > > unjoin0([C|Cs]) -> > [[C] | unjoin0(Cs)]; > unjoin0([]) -> > []. > > %% Split a string at a single character separator. > > unjoin1(String, Sep) -> > unjoin1_loop(String, Sep, ""). > > unjoin1_loop([Sep|String], Sep, Rev) -> > [lists:reverse(Rev) | unjoin1(String, Sep)]; > unjoin1_loop([Chr|String], Sep, Rev) -> > unjoin1_loop(String, Sep, [Chr|Rev]); > unjoin1_loop([], _, Rev) -> > [lists:reverse(Rev)]. > > %% Split a string at a multi-character separator > %% [C1,C2|L]. These components are split out for > %% a fast match. > > unjoin2(String, C1, C2, L) -> > unjoin2_loop(String, C1, C2, L, ""). > > unjoin2_loop([C1|S = [C2|String]], C1, C2, L, Rev) -> > case unjoin_prefix(L, String) > of no -> unjoin2_loop(S, C1, C2, L, [C1|Rev]) > ; Rest -> [lists:reverse(Rev) | unjoin2(Rest, C1, C2, L)] > end; > unjoin2_loop([Chr|String], C1, C2, L, Rev) -> > unjoin2_loop(String, C1, C2, L, [Chr|Rev]); > unjoin2_loop([], _, _, _, Rev) -> > [lists:reverse(Rev)]. > > unjoin_prefix([C|L], [C|S]) -> unjoin_prefix(L, S); > unjoin_prefix([], S) -> S; > unjoin_prefix(_, _) -> no. > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/bf2f7dac/attachment-0001.html From raimo+erlang-questions Thu Oct 9 08:50:59 2008 From: raimo+erlang-questions (Raimo Niskanen) Date: Thu, 9 Oct 2008 08:50:59 +0200 Subject: [erlang-questions] : pid to integer and back In-Reply-To: <09C01AA9-EA01-4CBE-AAC3-BF4054D4958A@gmail.com> References: <20081008161406.6F7D12402F@relay.gooddata.com> <20081008165429.4EDD12402F@relay.gooddata.com> <09C01AA9-EA01-4CBE-AAC3-BF4054D4958A@gmail.com> Message-ID: <20081009065059.GA27055@erix.ericsson.se> On Wed, Oct 08, 2008 at 07:10:33PM +0100, Joel Reymont wrote: > > On Oct 8, 2008, at 5:54 PM, Hynek Vychodil wrote: > > > Use term_to_binary and just remove starting 131, 130 and following > > node > > information, you take 9 bytes and use this. Or you can get only ID > > part > > which is only 4bytes. > > That would work. I have a question, though... Under what conditions > can the serial portion of the PID change? That would be the Z in > . For many enough processes. Due to backwards comp... you have heard it before, Y is the 15 least significant bits of the process index, and Z the more significant. And X is the external node index, so on the home node of a process, X is 0. > > Thanks, Joel > > -- > wagerlabs.com > > > > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions -- / Raimo Niskanen, Erlang/OTP, Ericsson AB From erlang-questions_efine Thu Oct 9 08:54:21 2008 From: erlang-questions_efine (Edwin Fine) Date: Thu, 9 Oct 2008 02:54:21 -0400 Subject: [erlang-questions] [enhancement] string:split/2 In-Reply-To: <34A27838-5CBA-425D-97A1-C2D2CF6F5456@cs.otago.ac.nz> References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> <34A27838-5CBA-425D-97A1-C2D2CF6F5456@cs.otago.ac.nz> Message-ID: <6c2563b20810082354u34372510n1fb4e1d23d777c23@mail.gmail.com> On Thu, Oct 9, 2008 at 12:37 AM, Richard O'Keefe wrote: > Colour me stupid. > I just realised, 40+ minute late, > what Fine meant about "idempotent" and why it matters. That'll learn me not to use big words I don't understand. > The requirement is that > for all strings String and Separator > for all Substring <- unjoin(String, Separator) > unjoin(Substring, Separator) =:= [Substring] > > This _isn't_ idempotence, but it's some sort of cousin > to it. And this is why unjoin("abc", "") doesn't > include empty matches at the beginning and end, so that > unjoin("a", "") =:= ["a"]. > Yeah, that's what I meant right there. Is there a big word for that? Impotent? Um, no, I don't think so. Let's see, "idem" is Latin for "the same".. I believe Greek for "the same" is "homo" (homogeneous?)... how about "homopotent"? Doesn't sound right ... -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/b7fc8830/attachment.html From bengt.kleberg Thu Oct 9 09:03:27 2008 From: bengt.kleberg (Bengt Kleberg) Date: Thu, 09 Oct 2008 09:03:27 +0200 Subject: [erlang-questions] Adding simple process to supervisor? Message-ID: <1223535807.3831.36.camel@seasc0642.dyn.rnd.as.sw.ericsson.se> Greetings, I have a gen_server which is supervised according to OTP rules. Now I want to add a simple process that will read from a TCP port and send the incoming data to the gen_server. I could spawn_link this process from the gen_server and restart it if it dies. However, since I have a supervisor it seems more logical to just add the process there, as a rest_for_one. There is the alternative of using a supervisor_bridge, but that seems more complex than using the gen_server. It seems as if I just design my process according to the OTP rules I will not need to use a supervisor_bridge. What are those rules? The only suggestions I have found are: 1 Module:start_link/1 => {ok, Pid} 2 Module:terminate/2 => ok The child specification returned by the init/1 call-back in a supervisor mentions the value for Modules if we have a gen_server, gen_fsm or gen_event. What could be used for a simple process? But how do I add a simple process to the supervisor? It seems overkill to masquerade it as a get_fsm or similar. Since it is not called from erlang it is not a gen_server. Since it does not have state it is not a gen_fsm. No events are handled. bengt From bgustavsson Thu Oct 9 09:59:12 2008 From: bgustavsson (Bjorn Gustavsson) Date: Thu, 9 Oct 2008 09:59:12 +0200 Subject: [erlang-questions] Extracting capture group names from regular expressions In-Reply-To: References: Message-ID: <6672d0160810090059v56e82766h8af0f8ae46831c42@mail.gmail.com> 2008/10/7 Tony Arcieri > I'm trying to write an API which accepts a regexp with arbitrary named > capture groups as input. > > I'm using the re module, and have had success using named subgroups if the > names are known ahead of time. However, I'd like to return a mapping of > arbitrary named capture groups from the original regular expression to the > matched values. > > Consider the following regular expression with named subpatterns: > > "(?\\w+) (?\\w+)" > > If this were applied to the string "baz qux" I'd like to return the > following: > > [{"foo", "baz"}, {"bar", "qux"}] > > However, it looks as if I must provide the names of the capture groups I > want returned in the capture tuple I pass to re:run. > > Is there any way to extract the names of the subgroups from a compiled > regular expression? Or is there some option I can pass to re:run that I'm > missing which will return a mapping of subgroup names to what they matched? > > There is currently no such option or functionality. It could be added in a future release if it's a general need. /Bjorn -- Bj?rn Gustavsson, Erlang/OTP, Ericsson AB -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/987e3e22/attachment.html From joelr1 Thu Oct 9 10:56:31 2008 From: joelr1 (Joel Reymont) Date: Thu, 9 Oct 2008 09:56:31 +0100 Subject: [erlang-questions] pid to integer and back In-Reply-To: References: <940411B6-1443-45EC-AF37-BB0ADFEAEBD6@gmail.com> <489F4BB7-4F92-456A-822A-555E05289C5C@gmail.com> Message-ID: On Oct 9, 2008, at 9:37 AM, Torben Hoffmann wrote: > did you ever get around to documenting Open Poker in > greater detail? Or are you busy making mone?!?! ;-) I'm busy coding so that I can finally make _real_ money and no, I don't want to impose AMPQ on the OpenPoker client implementors. Thanks for the suggestions, though. -- wagerlabs.com From twoggle Thu Oct 9 11:04:44 2008 From: twoggle (Tim Fletcher) Date: Thu, 9 Oct 2008 02:04:44 -0700 (PDT) Subject: [erlang-questions] [enhancement] string:split/2 In-Reply-To: <6c2563b20810082354u34372510n1fb4e1d23d777c23@mail.gmail.com> References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> <34A27838-5CBA-425D-97A1-C2D2CF6F5456@cs.otago.ac.nz> <6c2563b20810082354u34372510n1fb4e1d23d777c23@mail.gmail.com> Message-ID: <781bce43-97e9-48fb-bba2-0ce230f2011a@t39g2000prh.googlegroups.com> > Yeah, that's what I meant right there. Is there a big word for that? > Impotent? Um, no, I don't think so. Let's see, "idem" is Latin for "the > same".. I believe Greek for "the same" is "homo" (homogeneous?)... how about > "homopotent"? Doesn't sound right ... Do you mean that string:split should be the _inverse_ of string:join? http://en.wikipedia.org/wiki/Inverse_function From rvirding Thu Oct 9 11:54:13 2008 From: rvirding (Robert Virding) Date: Thu, 9 Oct 2008 11:54:13 +0200 Subject: [erlang-questions] [enhancement] string:split/2 In-Reply-To: References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> Message-ID: <3dbc6d1c0810090254q6a75d971o5752178126d21e34@mail.gmail.com> 2008/10/9 Richard O'Keefe > > (3) unjoin:unjoin(";;;abc;;de;f;g;;", ";;"). > [[],";abc","de;f;g",[]] > > Is that the right answer, or should it be > [";","abc","de;f;g",[]]? Either, depending on how you define your string. It could either start/end with a separator, or start/end with data. The important thing is to define it and should be the same at either end. For example regular expression libraries often have start/end with data. Your first example is start/end with data, while your second is start/end with separator. I would personally prefer the name split even though unjoin might more correct. Looking at the documentation for string:join it is start/end data so I definitely feel that split/unjoin should do the same so that they are inverses. Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/4040029b/attachment.html From erlangy Thu Oct 9 12:59:51 2008 From: erlangy (ERLANG) Date: Thu, 9 Oct 2008 12:59:51 +0200 Subject: [erlang-questions] External file sorting Message-ID: Hi List, Is there some free Erlang code for external (i.e on disk) file sorting? cheers Y. From joelr1 Thu Oct 9 13:08:01 2008 From: joelr1 (Joel Reymont) Date: Thu, 9 Oct 2008 12:08:01 +0100 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names Message-ID: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> I'm still trying to figure out how to optimize pid <-> integer mapping and I thought I'd try several approaches. My goal is to lookup a process id as quickly as possible given an integer. My system is a Mac Pro 2x2.8Ghz Quad Xeon, 14Gb of memory Erlang (BEAM) emulator version 5.6.3 [source] [smp:8] [async-threads: 0] [kernel-poll:false] Here's my set of timings, code at the end of this message. %% gb_trees 1> map1:test(10000). Populate: 0.0972 Lookup: 0.0912 ok 2> map1:test(100000). Populate: 0.8737 Lookup: 5.0007 ok 3> map1:test(1000000). Populate: 9.9215 Lookup: 5.0010 ok %% dict 1> map2:test(10000). Populate: 0.1035 Lookup: 0.0730 ok 2> map2:test(100000). Populate: 1.0407 Lookup: 1.2715 ok 3> map2:test(1000000). Populate: 10.5010 Lookup: 5.0010 ok %% ets 4> map3:test(10000). Populate: 0.1140 Lookup: 0.0448 ok 5> map3:test(100000). Populate: 1.3435 Lookup: 0.4669 ok 6> map3:test(1000000). Populate: 11.6472 Lookup: 5.0860 ok Dict seems to be the winner for 100K values. What's particularly interesting to me is that gb_trees, dict and ets give take about the same time to look up 1 mil. values. Is there an explanation? map4, map5 and map6 that test mnesia ram_copies, disc_only_copies and ram_copies in a 2-node setup. There seems to be no overhead compared to ets, though. Can't explain this either. The absolutely bizarre and surprising discovery are the timings for registered names. On a hunch, I thought I'd try to register a process under its id. This way I could just send messages to that id from any node in the cluster, without having to go through a separate translation process. %% registered names (2)2> map7:test(10000). Populate: 0.8526 Lookup: 0.0040 ok (2)1> map7:test(100000). Populate: 8.8507 Lookup: 0.0605 ok (2)3> map7:test(1000000). Populate: 94.6030 Lookup: 0.8558 It seems that registering processes under their integer id is the way to go. Am I right in my conclusion? Are there any pitfalls with going this route? Between players and games, I would most likely have <100K ids registered at any given time. Code in follow-up messages, registered names first, then gb_trees, dict, ets and mnesia. Thanks, Joel -- wagerlabs.com From joelr1 Thu Oct 9 13:08:54 2008 From: joelr1 (Joel Reymont) Date: Thu, 9 Oct 2008 12:08:54 +0100 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> Message-ID: %%% gb_trees -module(map1). -behaviour(gen_server). -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -export([start/0, test/1, populate/2, lookup/2]). -record(data, { xref }). start() -> gen_server:start(map1, [], []). init([]) -> {ok, #data{ xref = gb_trees:empty() }}. terminate(_, _) -> ok. handle_cast({'ADD', Key, Val}, Data) -> Xref = Data#data.xref, {noreply, Data#data{ xref = gb_trees:enter(Key, Val, Xref) }}; handle_cast(stop, Data) -> {stop, normal, Data}. handle_call({'LOOKUP', Key}, _From, Data) -> {reply, gb_trees:get(Key, Data#data.xref), Data}. handle_info(Info, Data) -> error_logger:info_report([{module, ?MODULE}, {line, ?LINE}, {self, self()}, {message, Info}]), {noreply, Data}. code_change(_, Data, _) -> {ok, Data}. test(N) -> {ok, Pid} = start(), {T1, _} = timer:tc(map1, populate, [Pid, N]), {T2, _} = timer:tc(map1, lookup, [Pid, N]), io:format("Populate: ~.4. f~n", [T1 / 1000000]), io:format("Lookup: ~.4. f~n", [T2 / 1000000]), gen_server:cast(Pid, stop). populate(_, 0) -> ok; populate(Pid, N) -> gen_server:cast(Pid, {'ADD', N, N}), populate(Pid, N - 1). lookup(_, 0) -> ok; lookup(Pid, N) -> gen_server:call(Pid, {'LOOKUP', N}), lookup(Pid, N - 1). From joelr1 Thu Oct 9 13:09:26 2008 From: joelr1 (Joel Reymont) Date: Thu, 9 Oct 2008 12:09:26 +0100 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> Message-ID: %%% dict -module(map2). -behaviour(gen_server). -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -export([start/0, test/1, populate/2, lookup/2]). -record(data, { xref }). start() -> gen_server:start(map2, [], []). init([]) -> {ok, #data{ xref = dict:new() }}. terminate(_, _) -> ok. handle_cast({'ADD', Key, Val}, Data) -> Xref = Data#data.xref, {noreply, Data#data{ xref = dict:store(Key, Val, Xref) }}; handle_cast(stop, Data) -> {stop, normal, Data}. handle_call({'LOOKUP', Key}, _From, Data) -> {reply, dict:fetch(Key, Data#data.xref), Data}. handle_info(Info, Data) -> error_logger:info_report([{module, ?MODULE}, {line, ?LINE}, {self, self()}, {message, Info}]), {noreply, Data}. code_change(_, Data, _) -> {ok, Data}. test(N) -> {ok, Pid} = start(), {T1, _} = timer:tc(map2, populate, [Pid, N]), {T2, _} = timer:tc(map2, lookup, [Pid, N]), io:format("Populate: ~.4. f~n", [T1 / 1000000]), io:format("Lookup: ~.4. f~n", [T2 / 1000000]), gen_server:cast(Pid, stop). populate(_, 0) -> ok; populate(Pid, N) -> gen_server:cast(Pid, {'ADD', N, N}), populate(Pid, N - 1). lookup(_, 0) -> ok; lookup(Pid, N) -> gen_server:call(Pid, {'LOOKUP', N}), lookup(Pid, N - 1). From joelr1 Thu Oct 9 13:10:05 2008 From: joelr1 (Joel Reymont) Date: Thu, 9 Oct 2008 12:10:05 +0100 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> Message-ID: <5E3032AF-1710-4173-BBA6-6435D5A2DB1A@gmail.com> %%% ets -module(map3). -behaviour(gen_server). -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -export([start/0, test/1, populate/2, lookup/2]). -record(data, { xref }). start() -> gen_server:start(map3, [], []). init([]) -> {ok, #data{ xref = ets:new(xref, []) }}. terminate(_, _) -> ok. handle_cast({'ADD', Key, Val}, Data) -> ets:insert(Data#data.xref, [{Key, Val}]), {noreply, Data}; handle_cast(stop, Data) -> {stop, normal, Data}. handle_call({'LOOKUP', Key}, _From, Data) -> [Value] = ets:lookup(Data#data.xref, Key), {reply, Value, Data}. handle_info(Info, Data) -> error_logger:info_report([{module, ?MODULE}, {line, ?LINE}, {self, self()}, {message, Info}]), {noreply, Data}. code_change(_, Data, _) -> {ok, Data}. test(N) -> {ok, Pid} = start(), {T1, _} = timer:tc(map3, populate, [Pid, N]), {T2, _} = timer:tc(map3, lookup, [Pid, N]), io:format("Populate: ~.4. f~n", [T1 / 1000000]), io:format("Lookup: ~.4. f~n", [T2 / 1000000]), gen_server:cast(Pid, stop). populate(_, 0) -> ok; populate(Pid, N) -> gen_server:cast(Pid, {'ADD', N, N}), populate(Pid, N - 1). lookup(_, 0) -> ok; lookup(Pid, N) -> gen_server:call(Pid, {'LOOKUP', N}), lookup(Pid, N - 1). From joelr1 Thu Oct 9 13:10:52 2008 From: joelr1 (Joel Reymont) Date: Thu, 9 Oct 2008 12:10:52 +0100 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> Message-ID: %%% mnesia ram_copies -module(map4). -behaviour(gen_server). -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -export([start/0, test/1, populate/2, lookup/2]). -record(xref, { key, val }). start() -> gen_server:start(map4, [], []). init([]) -> {ok, none}. terminate(_, _) -> ok. handle_cast({'ADD', Key, Val}, Data) -> F = fun() -> mnesia:write(#xref{ key = Key, val = Val}) end, mnesia:transaction(F), {noreply, Data}; handle_cast(stop, Data) -> {stop, normal, Data}. handle_call({'LOOKUP', Key}, _From, Data) -> F = fun() -> mnesia:read({xref, Key}) end, {atomic, [Value]} = mnesia:transaction(F), {reply, Value, Data}. handle_info(Info, Data) -> error_logger:info_report([{module, ?MODULE}, {line, ?LINE}, {self, self()}, {message, Info}]), {noreply, Data}. code_change(_, Data, _) -> {ok, Data}. test(N) -> mnesia:stop(), mnesia:delete_schema([node()]), mnesia:create_schema([node()]), mnesia:start(), {atomic, ok} = mnesia:create_table(xref, [ {ram_copies, [node()]}, {type, set}, {attributes, record_info(fields, xref)} ]), {ok, Pid} = start(), {T1, _} = timer:tc(map4, populate, [Pid, N]), {T2, _} = timer:tc(map4, lookup, [Pid, N]), io:format("Populate: ~.4. f~n", [T1 / 1000000]), io:format("Lookup: ~.4. f~n", [T2 / 1000000]), gen_server:cast(Pid, stop). populate(_, 0) -> ok; populate(Pid, N) -> gen_server:cast(Pid, {'ADD', N, N}), populate(Pid, N - 1). lookup(_, 0) -> ok; lookup(Pid, N) -> gen_server:call(Pid, {'LOOKUP', N}), lookup(Pid, N - 1). From joelr1 Thu Oct 9 13:12:22 2008 From: joelr1 (Joel Reymont) Date: Thu, 9 Oct 2008 12:12:22 +0100 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> Message-ID: <310AE5D4-2D20-4763-87B2-92BD228B30D0@gmail.com> %%% mnesia disc_only_copies -module(map5). -behaviour(gen_server). -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -export([start/0, test/1, populate/2, lookup/2]). -record(xref, { key, val }). start() -> gen_server:start(map5, [], []). init([]) -> {ok, none}. terminate(_, _) -> ok. handle_cast({'ADD', Key, Val}, Data) -> F = fun() -> mnesia:write(#xref{ key = Key, val = Val}) end, mnesia:transaction(F), {noreply, Data}; handle_cast(stop, Data) -> {stop, normal, Data}. handle_call({'LOOKUP', Key}, _From, Data) -> F = fun() -> mnesia:read({xref, Key}) end, {atomic, [Value]} = mnesia:transaction(F), {reply, Value, Data}. handle_info(Info, Data) -> error_logger:info_report([{module, ?MODULE}, {line, ?LINE}, {self, self()}, {message, Info}]), {noreply, Data}. code_change(_, Data, _) -> {ok, Data}. test(N) -> mnesia:stop(), mnesia:delete_schema([node()]), mnesia:create_schema([node()]), mnesia:start(), {atomic, ok} = mnesia:create_table(xref, [ {disc_only_copies, [node()]}, {type, set}, {attributes, record_info(fields, xref)} ]), {ok, Pid} = start(), {T1, _} = timer:tc(map5, populate, [Pid, N]), {T2, _} = timer:tc(map5, lookup, [Pid, N]), io:format("Populate: ~.4. f~n", [T1 / 1000000]), io:format("Lookup: ~.4. f~n", [T2 / 1000000]), gen_server:cast(Pid, stop). populate(_, 0) -> ok; populate(Pid, N) -> gen_server:cast(Pid, {'ADD', N, N}), populate(Pid, N - 1). lookup(_, 0) -> ok; lookup(Pid, N) -> gen_server:call(Pid, {'LOOKUP', N}), lookup(Pid, N - 1). From joelr1 Thu Oct 9 13:13:26 2008 From: joelr1 (Joel Reymont) Date: Thu, 9 Oct 2008 12:13:26 +0100 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> Message-ID: <1F60C446-258F-4F99-A901-84045DE8DEE5@gmail.com> %%% mnesia ram_copies that can be used in a distributed scenario -module(map6). -behaviour(gen_server). -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -export([start/0, test/1, populate/2, lookup/2, setup1/1]). -record(xref, { key, val }). start() -> gen_server:start(map6, [], []). init([]) -> {ok, none}. terminate(_, _) -> ok. handle_cast({'ADD', Key, Val}, Data) -> F = fun() -> mnesia:write(#xref{ key = Key, val = Val}) end, mnesia:transaction(F), {noreply, Data}; handle_cast(stop, Data) -> {stop, normal, Data}. handle_call({'LOOKUP', Key}, _From, Data) -> F = fun() -> mnesia:read({xref, Key}) end, {atomic, [Value]} = mnesia:transaction(F), {reply, Value, Data}. handle_info(Info, Data) -> error_logger:info_report([{module, ?MODULE}, {line, ?LINE}, {self, self()}, {message, Info}]), {noreply, Data}. code_change(_, Data, _) -> {ok, Data}. setup1(Nodes) -> mnesia:stop(), mnesia:delete_schema(Nodes), mnesia:create_schema(Nodes), mnesia:start(), {atomic, ok} = mnesia:create_table(xref, [ {ram_copies, Nodes}, {type, set}, {attributes, record_info(fields, xref)} ]). test(N) -> {ok, Pid} = start(), {T1, _} = timer:tc(map6, populate, [Pid, N]), {T2, _} = timer:tc(map6, lookup, [Pid, N]), io:format("Populate: ~.4. f~n", [T1 / 1000000]), io:format("Lookup: ~.4. f~n", [T2 / 1000000]), gen_server:cast(Pid, stop). populate(_, 0) -> ok; populate(Pid, N) -> gen_server:cast(Pid, {'ADD', N, N}), populate(Pid, N - 1). lookup(_, 0) -> ok; lookup(Pid, N) -> gen_server:call(Pid, {'LOOKUP', N}), lookup(Pid, N - 1). From joelr1 Thu Oct 9 13:14:12 2008 From: joelr1 (Joel Reymont) Date: Thu, 9 Oct 2008 12:14:12 +0100 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> Message-ID: %%% and finally, the moment you have all been waiting for! %%% ... %%% registered names -module(map7). -behaviour(gen_server). -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -export([start/1, test/1, populate/1, lookup/1]). start(N) -> gen_server:start({global, N}, map7, [], []). init([]) -> {ok, none}. terminate(_, _) -> ok. handle_cast(stop, Data) -> {stop, normal, Data}. handle_call(Event, From, Data) -> error_logger:info_report([{module, ?MODULE}, {line, ?LINE}, {self, self()}, {event, Event}, {from, From} ]), {noreply, Data}. handle_info(Info, Data) -> error_logger:info_report([{module, ?MODULE}, {line, ?LINE}, {self, self()}, {message, Info}]), {noreply, Data}. code_change(_, Data, _) -> {ok, Data}. test(N) -> {T1, _} = timer:tc(map7, populate, [N]), {T2, _} = timer:tc(map7, lookup, [N]), io:format("Populate: ~.4. f~n", [T1 / 1000000]), io:format("Lookup: ~.4. f~n", [T2 / 1000000]), stop(N). populate(0) -> ok; populate(N) -> {ok, _} = start(N), populate(N - 1). lookup(0) -> ok; lookup(N) -> P = global:whereis_name(N), lookup(N - 1). stop(0) -> ok; stop(N) -> gen_server:cast({global, N}, stop), stop(N - 1). From joelr1 Thu Oct 9 13:18:38 2008 From: joelr1 (Joel Reymont) Date: Thu, 9 Oct 2008 12:18:38 +0100 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> Message-ID: <1D12F980-BEA2-4356-84BA-A2B373BBE7B4@gmail.com> %% mnesia disc_only_copies (1)5> map5:test(10000). Populate: 0.1501 Lookup: 5.0008 ok (1)6> map5:test(100000). Populate: 1.2503 Lookup: 5.0002 ok (1)7> map5:test(1000000). Populate: 10.1628 Lookup: 5.0006 ok Is there a bug in my code? I thought disk access was supposed to be much slower! From ulf.wiger Thu Oct 9 13:24:16 2008 From: ulf.wiger (Ulf Wiger (TN/EAB)) Date: Thu, 09 Oct 2008 13:24:16 +0200 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> Message-ID: <48EDE9E0.1080606@ericsson.com> Joel Reymont skrev: > > The absolutely bizarre and surprising discovery are the timings for > registered names. On a hunch, I thought I'd try to register a process > under its id. This way I could just send messages to that id from any > node in the cluster, without having to go through a separate > translation process. The only thing to think about, perhaps, is that global doesn't scale well when you add more nodes. If you have only one node, it's very fast indeed. See e.g. the benchmark figures given in my Gproc paper, pg 9: http://svn.ulf.wiger.net/gproc/doc/erlang07-wiger.pdf BR, Ulf W From joelr1 Thu Oct 9 13:16:18 2008 From: joelr1 (Joel Reymont) Date: Thu, 9 Oct 2008 12:16:18 +0100 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> Message-ID: %%% mnesia ram_copies (1)2> map4:test(10000). Populate: 0.1463 Lookup: 4.7873 ok (1)3> map4:test(100000). Populate: 1.5338 Lookup: 5.0010 ok (1)4> map4:test(1000000). Populate: 12.3123 Lookup: 5.0009 ok About the same as map3/ets. Not surprising, since ram_copies _is_ ets. From joelr1 Thu Oct 9 13:26:33 2008 From: joelr1 (Joel Reymont) Date: Thu, 9 Oct 2008 12:26:33 +0100 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> Message-ID: %% mnesia ram_copies on two nodes %% node #1 mothership:opti joelr$ erl -sname 1 (1)1> map6:setup1(['1', '2']). {atomic,ok} (1)2> mnesia:info(). ... ---> Active tables <--- schema : with 2 records occupying 553 words of mem xref : with 0 records occupying 312 words of mem ... running db nodes = ['2','1'] ... [{'1',ram_copies},{'2',ram_copies}] = [xref,schema] 5 transactions committed, 0 aborted, 0 restarted, 0 logged to disc 0 held locks, 0 in queue; 0 local transactions, 0 remote 0 transactions waits for other nodes: [] ok %% node #2 mothership:opti joelr$ erl -sname 2 (2)2> mnesia:start(). ok (2)3> mnesia:change_config(extra_db_nodes, ['1']). {ok,['1']} (2)4> mnesia:info(). ... ---> Active tables <--- schema : with 2 records occupying 553 words of mem xref : with 0 records occupying 312 words of mem ... running db nodes = ['1','2'] ... [{'1',ram_copies},{'2',ram_copies}] = [xref,schema] 5 transactions committed, 0 aborted, 0 restarted, 0 logged to disc 0 held locks, 0 in queue; 0 local transactions, 0 remote 0 transactions waits for other nodes: [] ok %% node #1 (1)3> map6:test(10000). Populate: 0.1193 Lookup: 5.0006 ok (1)4> map6:test(100000). Populate: 1.4206 Lookup: 5.0003 ok (1)5> map6:test(1000000). Populate: 1.8590 Lookup: 5.0009 ok No difference from ets and mnesia ram_copies on a single node! Here's proof that we did commit to the other node: %% node #2 (2)5> mnesia:info(). ---> Processes holding locks <--- Lock: {{xref,93850},write,{tid,16678,<5738.84.0>}} Lock: {{xref,999482},write,{tid,16671,<5738.86.0>}} ---> Participant transactions <--- Tid: 16671 (owned by <5738.86.0>) with participant objects {commit,'2',presume_commit, [{{xref,999482},{xref, 999482,999482},write}], [],[],[],[],[]} ---> Active tables <--- schema : with 2 records occupying 553 words of mem xref : with 16668 records occupying 186219 words of mem ... 5 transactions committed, 0 aborted, 0 restarted, 0 logged to disc 2 held locks, 0 in queue; 0 local transactions, 1 remote 0 transactions waits for other nodes: [] ok From vychodil.hynek Thu Oct 9 13:34:12 2008 From: vychodil.hynek (Hynek Vychodil) Date: Thu, 9 Oct 2008 13:34:12 +0200 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> Message-ID: <20081009113413.775B92402F@relay.gooddata.com> Did you test if returned values from global:whereis_name is correct? You should do it especially when you don't believe benchmark result. You should check return value from each function call if you want trust your code. It can catch big amount of weird errors. On Thu, Oct 9, 2008 at 1:14 PM, Joel Reymont wrote: > %%% and finally, the moment you have all been waiting for! > %%% ... > %%% registered names > > -module(map7). > -behaviour(gen_server). > > -export([init/1, handle_call/3, handle_cast/2, > handle_info/2, terminate/2, code_change/3]). > > -export([start/1, test/1, populate/1, lookup/1]). > > start(N) -> > gen_server:start({global, N}, map7, [], []). > > init([]) -> > {ok, none}. > > terminate(_, _) -> > ok. > > handle_cast(stop, Data) -> > {stop, normal, Data}. > > handle_call(Event, From, Data) -> > error_logger:info_report([{module, ?MODULE}, > {line, ?LINE}, > {self, self()}, > {event, Event}, > {from, From} > ]), > {noreply, Data}. > > handle_info(Info, Data) -> > error_logger:info_report([{module, ?MODULE}, > {line, ?LINE}, > {self, self()}, > {message, Info}]), > {noreply, Data}. > > code_change(_, Data, _) -> > {ok, Data}. > > test(N) -> > {T1, _} = timer:tc(map7, populate, [N]), > {T2, _} = timer:tc(map7, lookup, [N]), > io:format("Populate: ~.4. f~n", [T1 / 1000000]), > io:format("Lookup: ~.4. f~n", [T2 / 1000000]), > stop(N). > > populate(0) -> > ok; > > populate(N) -> > {ok, _} = start(N), > populate(N - 1). > > lookup(0) -> > ok; > > lookup(N) -> > P = global:whereis_name(N), > lookup(N - 1). > > stop(0) -> > ok; > > stop(N) -> > gen_server:cast({global, N}, stop), > stop(N - 1). > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -- --Hynek (Pichi) Vychodil -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/46d6938a/attachment.html From joelr1 Thu Oct 9 13:44:09 2008 From: joelr1 (Joel Reymont) Date: Thu, 9 Oct 2008 12:44:09 +0100 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: <48EDE9E0.1080606@ericsson.com> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> <48EDE9E0.1080606@ericsson.com> Message-ID: <1A33E093-7C86-4E8E-BDB3-52E5971D5912@gmail.com> On Oct 9, 2008, at 12:24 PM, Ulf Wiger (TN/EAB) wrote: > The only thing to think about, perhaps, is that global doesn't > scale well when you add more nodes. If you have only one node, > it's very fast indeed. I thought I'd test with 4 nodes... (1)2> nodes(). ['2','3','4'] (1)3> map7:test(100000). Populate: 165.2079 Lookup: 0.0641 ok Not much of a difference, still super-efficient! -- wagerlabs.com From joelr1 Thu Oct 9 13:45:14 2008 From: joelr1 (Joel Reymont) Date: Thu, 9 Oct 2008 12:45:14 +0100 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: <20081009113413.7492324022@relay.gooddata.com> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> <20081009113413.7492324022@relay.gooddata.com> Message-ID: <999BCDBE-DCA5-46F7-9AC0-BEE7BA1F735F@gmail.com> lookup(N) -> P = global:whereis_name(N), true = is_process_alive(P), lookup(N - 1). This should be enough for error checking, right? (1)4> c(map7). {ok,map7} (1)5> map7:test(100000). Populate: 265.2531 Lookup: 0.0831 ok The timings are not much off! -- wagerlabs.com From saleyn Thu Oct 9 13:48:02 2008 From: saleyn (Serge Aleynikov) Date: Thu, 09 Oct 2008 07:48:02 -0400 Subject: [erlang-questions] Adding simple process to supervisor? In-Reply-To: <1223535807.3831.36.camel@seasc0642.dyn.rnd.as.sw.ericsson.se> References: <1223535807.3831.36.camel@seasc0642.dyn.rnd.as.sw.ericsson.se> Message-ID: <48EDEF72.60907@gmail.com> You need to look into the proc_lib module, which serves the need you described. Search this list for "proc_lib and sys" http://www.erlang.org/pipermail/erlang-questions/2006-July/021526.html In addition to implementing a synchronous startup function (using proc_lib:init_ack({ok, self()}) in your Module:start_link/1), you'll need to support these three functions so that your process is an obedient citizen in the OTP system: system_continue/3, system_terminate/4, system_code_change/4 E.g.: http://www.erlang.org/pipermail/erlang-questions/2005-April/015224.html Serge Bengt Kleberg wrote: > Greetings, > > I have a gen_server which is supervised according to OTP rules. Now I > want to add a simple process that will read from a TCP port and send > the incoming data to the gen_server. I could spawn_link this process > from the gen_server and restart it if it dies. However, since I have a > supervisor it seems more logical to just add the process there, as a > rest_for_one. > > > There is the alternative of using a supervisor_bridge, but that seems > more complex than using the gen_server. It seems as if I just design > my process according to the OTP rules I will not need to use a > supervisor_bridge. What are those rules? The only suggestions I have > found are: > 1 Module:start_link/1 => {ok, Pid} > 2 Module:terminate/2 => ok > > > The child specification returned by the init/1 call-back in a > supervisor mentions the value for Modules if we have a gen_server, > gen_fsm or gen_event. What could be used for a simple process? > > > But how do I add a simple process to the supervisor? It seems overkill > to masquerade it as a get_fsm or similar. Since it is not called from > erlang it is not a gen_server. Since it does not have state it is not a > gen_fsm. No events are handled. > > > bengt > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From saleyn Thu Oct 9 14:03:28 2008 From: saleyn (Serge Aleynikov) Date: Thu, 09 Oct 2008 08:03:28 -0400 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: <999BCDBE-DCA5-46F7-9AC0-BEE7BA1F735F@gmail.com> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> <20081009113413.7492324022@relay.gooddata.com> <999BCDBE-DCA5-46F7-9AC0-BEE7BA1F735F@gmail.com> Message-ID: <48EDF310.20502@gmail.com> This doesn't make sense as calling is_process_alive/1 on a non-local Pid would throw an exception (meaning that all your pids are on the local node since you are not getting one). Joel Reymont wrote: > lookup(N) -> > P = global:whereis_name(N), > true = is_process_alive(P), > lookup(N - 1). > > This should be enough for error checking, right? > > (1)4> c(map7). > {ok,map7} > (1)5> map7:test(100000). > Populate: 265.2531 > Lookup: 0.0831 > ok > > The timings are not much off! > > -- > wagerlabs.com > > > > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From ulf.wiger Thu Oct 9 14:05:54 2008 From: ulf.wiger (Ulf Wiger (TN/EAB)) Date: Thu, 09 Oct 2008 14:05:54 +0200 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: <999BCDBE-DCA5-46F7-9AC0-BEE7BA1F735F@gmail.com> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> <20081009113413.7492324022@relay.gooddata.com> <999BCDBE-DCA5-46F7-9AC0-BEE7BA1F735F@gmail.com> Message-ID: <48EDF3A2.4000006@ericsson.com> Joel Reymont skrev: > lookup(N) -> > P = global:whereis_name(N), > true = is_process_alive(P), > lookup(N - 1). > > This should be enough for error checking, right? > > (1)4> c(map7). > {ok,map7} > (1)5> map7:test(100000). > Populate: 265.2531 > Lookup: 0.0831 > ok > > The timings are not much off! How many nodes did you have there? > I thought I'd test with 4 nodes... > > (1)2> nodes(). > ['2','3','4'] > (1)3> map7:test(100000). > Populate: 165.2079 > Lookup: 0.0641 > ok > > Not much of a difference, still super-efficient! It seems as if you have quite a large variation on the populate benchmark - esp if the first test above is with only one node. Anyway, the worst part of global's algorithm is the random backoff at lock conflicts, but that shouldn't affect you in this particular case. BR, Ulf W From joelr1 Thu Oct 9 14:06:57 2008 From: joelr1 (Joel Reymont) Date: Thu, 9 Oct 2008 13:06:57 +0100 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: <1A33E093-7C86-4E8E-BDB3-52E5971D5912@gmail.com> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> <48EDE9E0.1080606@ericsson.com> <1A33E093-7C86-4E8E-BDB3-52E5971D5912@gmail.com> Message-ID: <17F15E0F-F779-4C91-833C-4261949E4210@gmail.com> The difference is that it took 165 seconds to globally register 100k processes on 4 nodes. The lookup time is still excellent, though! On Oct 9, 2008, at 12:44 PM, Joel Reymont wrote: > I thought I'd test with 4 nodes... > > (1)2> nodes(). > ['2','3','4'] > (1)3> map7:test(100000). > Populate: 165.2079 > Lookup: 0.0641 > ok -- wagerlabs.com From joelr1 Thu Oct 9 14:07:55 2008 From: joelr1 (Joel Reymont) Date: Thu, 9 Oct 2008 13:07:55 +0100 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: <48EDF310.20502@gmail.com> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> <20081009113413.7492324022@relay.gooddata.com> <999BCDBE-DCA5-46F7-9AC0-BEE7BA1F735F@gmail.com> <48EDF310.20502@gmail.com> Message-ID: <0F30EFA1-F6B5-48F6-AF6F-7206A4D3F311@gmail.com> On Oct 9, 2008, at 1:03 PM, Serge Aleynikov wrote: > This doesn't make sense as calling is_process_alive/1 on a non-local > Pid would throw an exception (meaning that all your pids are on the > local node since you are not getting one). For the purposes of testing, all my pids _are_ on the local node. -- wagerlabs.com From joelr1 Thu Oct 9 14:15:54 2008 From: joelr1 (Joel Reymont) Date: Thu, 9 Oct 2008 13:15:54 +0100 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: <48EDF3A2.4000006@ericsson.com> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> <20081009113413.7492324022@relay.gooddata.com> <999BCDBE-DCA5-46F7-9AC0-BEE7BA1F735F@gmail.com> <48EDF3A2.4000006@ericsson.com> Message-ID: On Oct 9, 2008, at 1:05 PM, Ulf Wiger (TN/EAB) wrote: > How many nodes did you have there? Same 4 nodes. > It seems as if you have quite a large variation on > the populate benchmark - esp if the first test above > is with only one node. No, there's no variation, it's the same 4 nodes. > Anyway, the worst part of global's algorithm is the > random backoff at lock conflicts, but that shouldn't > affect you in this particular case. Here's the version of the code I'm testing with 50 nodes now. Use start_slaves/1 with your desired number of nodes and try test/1 right after. I think it will be tomorrow before my 50 nodes and 100k processes test is done. --- -module(map8). -behaviour(gen_server). -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -export([start/1, test/1, populate/1, lookup/1, start_slaves/1]). start(N) -> gen_server:start({global, N}, map8, [], []). init([]) -> {ok, none}. terminate(_, _) -> ok. handle_cast(stop, Data) -> {stop, normal, Data}. handle_call(Event, From, Data) -> error_logger:info_report([{module, ?MODULE}, {line, ?LINE}, {self, self()}, {event, Event}, {from, From} ]), {noreply, Data}. handle_info(Info, Data) -> error_logger:info_report([{module, ?MODULE}, {line, ?LINE}, {self, self()}, {message, Info}]), {noreply, Data}. code_change(_, Data, _) -> {ok, Data}. test(N) -> {T1, _} = timer:tc(map8, populate, [N]), {T2, _} = timer:tc(map8, lookup, [N]), io:format("Populate: ~.4. f~n", [T1 / 1000000]), io:format("Lookup: ~.4. f~n", [T2 / 1000000]), stop(N). populate(0) -> ok; populate(N) -> {ok, _} = start(N), populate(N - 1). lookup(0) -> ok; lookup(N) -> P = global:whereis_name(N), true = is_process_alive(P), lookup(N - 1). stop(0) -> ok; stop(N) -> gen_server:cast({global, N}, stop), stop(N - 1). start_slaves(0) -> ok; start_slaves(N) -> Name = list_to_atom(integer_to_list(N)), Args = "", Node = start_slave_node(Name, Args), io:format("~p up running~n", [Node]), timer:sleep(100), start_slaves(N - 1). start_slave_node(Name, Args) -> {ok, Node} = slave:start_link(net_adm:localhost(), Name, Args), Node. -- wagerlabs.com From richardc Thu Oct 9 14:17:49 2008 From: richardc (Richard Carlsson) Date: Thu, 09 Oct 2008 14:17:49 +0200 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> Message-ID: <48EDF66D.9010101@it.uu.se> Joel Reymont wrote: > Dict seems to be the winner for 100K values. What's particularly > interesting to me is that gb_trees, dict and ets give take about the > same time to look up 1 mil. values. Is there an explanation? Joel, one of the problems with benchmarking is to be sure what it is that you measure. Your code for "populate" uses gen_server:cast, which basically means that what you measure is message passing time. Furthermore, for large numbers of messages, you start running the lookup test before the server has had time to process its huge in-queue, hence the strangely similar numbers 5.0xxx for most tests. The hint is that your numbers _should_ scale at least linearly with the number of elements, and that the lookup time should be the same for both 100k and 1000k elements is completely unreasonable. (The confirmation for me was that even though the test had completed, my cpu was still working like crazy until I shut down the VM again; the server was still processing a million backed up ADD-requests.) Changing cast to call in your code, I get this for dict and gb_trees: ---- map1:test(10000). Populate: 0.1408 Lookup: 0.0497 map1:test(100000). Populate: 1.9648 Lookup: 0.5244 map1:test(1000000). Populate: 34.2963 Lookup: 5.2909 ---- map2:test(10000). Populate: 0.1187 Lookup: 0.0519 map2:test(100000). Populate: 0.9676 Lookup: 0.5331 map2:test(1000000). Populate: 40.2369 Lookup: 5.8442 ---- These numbers make more sense: they scale with the number of elements, and gb_trees wins over dict. /Richard From joelr1 Thu Oct 9 14:27:30 2008 From: joelr1 (Joel Reymont) Date: Thu, 9 Oct 2008 13:27:30 +0100 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: <48EDF66D.9010101@it.uu.se> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> <48EDF66D.9010101@it.uu.se> Message-ID: On Oct 9, 2008, at 1:17 PM, Richard Carlsson wrote: > Changing cast to call in your code, I get this for dict and gb_trees: Richard, thank you for pointing out the flaw in my code. Still, note that the lookup time is still very very low. I'm not really concerned with the time to populate as my goal is to grab a number from every incoming packet and map that to a process id so that I can route the packet. I really like globally registered names since they take care of distributing the pids across the cluster. It doesn't seem they scale, though. -- wagerlabs.com From Dana.RUBINO Thu Oct 9 15:05:48 2008 From: Dana.RUBINO (Dana.RUBINO) Date: Thu, 9 Oct 2008 14:05:48 +0100 Subject: [erlang-questions] Erlang ODBC best practices Message-ID: Hi All, I am currently using an in-memory database which offers ODBC connectivity (Oracle Times Ten). Of course given I am using ODBC I need to generate and pass SQL commands to the DB. I was wondering what is the best way to organise SQL statements (canned) and build up dynamic SQL statements within Erlang? Currently I just have my static SQL commands in a .hrl file and as a crude example access them as such: odbc:start(), {ok, Ref} = odbc:connect("DSN=TT_HWHU;UID=aUID;PWD=aPWD", [{scrollable_cursors, off}]), {selected, ColNames, Data} = odbc:sql_query(Ref, ?TESTSQL), Does anyone know of a better way of doing this? In particular building up an SQL statement dynamically - for example in an insert statement? Many Thanks, Dan *********************************************************************************** The Royal Bank of Scotland plc. Registered in Scotland No 90312. Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB. Authorised and regulated by the Financial Services Authority This e-mail message is confidential and for use by the addressee only. If the message is received by anyone other than the addressee, please return the message to the sender by replying to it and then delete the message from your computer. Internet e-mails are not necessarily secure. The Royal Bank of Scotland plc does not accept responsibility for changes made to this message after it was sent. Whilst all reasonable care has been taken to avoid the transmission of viruses, it is the responsibility of the recipient to ensure that the onward transmission, opening or use of this message and any attachments will not adversely affect its systems or data. No responsibility is accepted by The Royal Bank of Scotland plc in this regard and the recipient should carry out such virus and other checks as it considers appropriate. Visit our websites at: www.rbs.com www.rbs.com/gbm www.rbsgc.com *********************************************************************************** -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/3c25a5dc/attachment.html From dot Thu Oct 9 14:35:23 2008 From: dot (Tony Finch) Date: Thu, 9 Oct 2008 13:35:23 +0100 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: <48EDF66D.9010101@it.uu.se> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> <48EDF66D.9010101@it.uu.se> Message-ID: On Thu, 9 Oct 2008, Richard Carlsson wrote: > > The hint is that your numbers _should_ scale at least linearly with > the number of elements, Shouldn't lookup be O(log n)? Tony. -- f.anthony.n.finch http://dotat.at/ SOLE: SOUTHERLY 5 TO 7, OCCASIONALLY GALE 8. MODERATE OR ROUGH, OCCASIONALLY VERY ROUGH IN WEST LATER. OCCASIONAL RAIN. MODERATE OR GOOD, OCCASIONALLY POOR. From erlang Thu Oct 9 15:18:07 2008 From: erlang (Joe Armstrong) Date: Thu, 9 Oct 2008 15:18:07 +0200 Subject: [erlang-questions] disk tests Message-ID: <9b08084c0810090618l5226d8b0m74bcfb92026e621d@mail.gmail.com> Hello, I've written a little program to test writing to disk - I need to create a number of large random access files and was running some tests when I ran into problems. As I write files to disk the erlang process grows and eventually I hit some kind of memory limits and the system slows to a crawl. It also has this behavior for sequential writes to disk. Also the data rate to disk is not as fast as I would have expected. Is this a bug or a feature? Here's a program that reproduces this. When I run disk_test:test() my system slows to a crawl. Can anybody explain what is happening here? Best /Joe -module(disk_test). %% Time-stamp: <2008-10-09 15:16:16 joe> -import(lists, [min/1, duplicate/2]). -compile(export_all). %% This program was supposed to test how fast I could write to disk %% but when I run it, it virtually stops the system. %% I create a 2 Meg file filled with zeros, then a 4 Meg file %% then a 6 Meg file and so on. %% By the time I get to creating a 40 MByte file the system has slowed to %% a crawl. The total data written at this point is around 500 Meg. %% If I watch the Memory usage my Erlang process has run up to 2GB of %% memory and the entire system crawls along. I then have to kill Erlang. %% The first few lines of output when I run this are as follows: %% > disk_test:test(). %% Creating a 2 Megabyte file %% {created,2,megs,in,0.225377,secs,8.874019975418966, %% megaBytesPerSec}. %% Creating a 4 Megabyte file %% {created,6,megs,in,0.49773,secs,12.054728467241276, %% megaBytesPerSec}. %% Creating a 6 Megabyte file %% {created,12,megs,in,0.930026,secs,12.902865081191278, %% megaBytesPerSec}. %% Creating a 8 Megabyte file %% {created,20,megs,in,1.461848,secs,13.681312968242937, %% megaBytesPerSec}. %% Creating a 10 Megabyte file %% {created,30,megs,in,2.213844,secs,13.551090320727207, %% megaBytesPerSec}. %% Creating a 12 Megabyte file %% {created,42,megs,in,2.926186,secs,14.353154584158355, %% megaBytesPerSec}. %% I'm managing to write about 12 MBytes/sec %% I suspect the disk is capable of about 70 MB/sec %% (just a guess) %% What's happening here? - why does the process size grow so large? test() -> make_file_seq(2,2,now_micros()). make_file_seq(N,_,_) when N > 60 -> true; make_file_seq(N,Tot,Tstart) -> make_file_seq0(N), Secs = duration(Tstart), Rate = Tot/Secs, io:format("~p.~n",[{created, Tot, megs,in, Secs,secs, Rate,megaBytesPerSec}]), make_file_seq(N+2, Tot+N+2, Tstart). duration(Tstart) -> (now_micros() - Tstart)/1000000. now_micros() -> {Mega,Sec,Micro} = erlang:now(), (Mega*1000000 + Sec)*1000000 + Micro. make_file_seq0(N) -> io:format("Creating a ~p Megabyte file~n",[N]), File = "tmp", file:delete(File), {ok, S} = file:open(File, [write]), Size = N * 1000000, zero_file_seqwrite(S, Size), file:close(S), Size = filelib:file_size(File). %% just checking :-) %% zero_file_seqwrite_seqwrite(FileHandle, Len) %% writes Len zeros to a file zero_file_seqwrite(S, Len) -> N = min([Len, 4096]), B = list_to_binary(duplicate(N, 0)), zero_file_seqwrite(S, Len, B, N). zero_file_seqwrite(S, Len, B, Size) when Size > Len -> file:write(S, [B]), zero_file_seqwrite(S, Len-Size, B, Size); zero_file_seqwrite(S, Len, _, _) -> B = list_to_binary(duplicate(Len, 0)), file:write(S, [B]). From richardc Thu Oct 9 15:32:09 2008 From: richardc (Richard Carlsson) Date: Thu, 09 Oct 2008 15:32:09 +0200 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> <48EDF66D.9010101@it.uu.se> Message-ID: <48EE07D9.5010508@it.uu.se> Tony Finch wrote: > On Thu, 9 Oct 2008, Richard Carlsson wrote: >> The hint is that your numbers _should_ scale at least linearly with >> the number of elements, > > Shouldn't lookup be O(log n)? Yes, if you do it once. But these runtimes were measured over n calls. (For populate, it gets a bit more complicated since the first operations work on a small dictionary and the last operations work on a huge one, but for lookup the total time should be a straightforward O(n*log n) for gb_trees.) /Richard From richardc Thu Oct 9 15:38:55 2008 From: richardc (Richard Carlsson) Date: Thu, 09 Oct 2008 15:38:55 +0200 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> <48EDF66D.9010101@it.uu.se> Message-ID: <48EE096F.6090307@it.uu.se> Joel Reymont wrote: > Richard, thank you for pointing out the flaw in my code. Still, note > that the lookup time is still very very low. > > I'm not really concerned with the time to populate as my goal is to > grab a number from every incoming packet and map that to a process id > so that I can route the packet. The main thing was just that you will not get any sensible numbers from the lookup measurement unless you have made sure that the population of the table has finished first. Otherwise you'll be measuring the time to look up nonexisting stuff, and for that most storage methods will do equally well. /Richard From vladdu55 Thu Oct 9 15:44:53 2008 From: vladdu55 (Vlad Dumitrescu) Date: Thu, 9 Oct 2008 15:44:53 +0200 Subject: [erlang-questions] Fwd: disk tests In-Reply-To: <9b08084c0810090618l5226d8b0m74bcfb92026e621d@mail.gmail.com> References: <9b08084c0810090618l5226d8b0m74bcfb92026e621d@mail.gmail.com> Message-ID: <95be1d3b0810090644j7dc7fc8es88ed4a5d17e495db@mail.gmail.com> Hi Joe, Shouldn't this > zero_file_seqwrite(S, Len, B, Size) when Size > Len -> be zero_file_seqwrite(S, Len, B, Size) when Size =< Len -> instead? The second version works completely fine. regards, Vlad From anders.nygren Thu Oct 9 15:55:57 2008 From: anders.nygren (Anders Nygren) Date: Thu, 9 Oct 2008 08:55:57 -0500 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: <48EE096F.6090307@it.uu.se> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> <48EDF66D.9010101@it.uu.se> <48EE096F.6090307@it.uu.se> Message-ID: On Thu, Oct 9, 2008 at 8:38 AM, Richard Carlsson wrote: > Joel Reymont wrote: >> Richard, thank you for pointing out the flaw in my code. Still, note >> that the lookup time is still very very low. >> >> I'm not really concerned with the time to populate as my goal is to >> grab a number from every incoming packet and map that to a process id >> so that I can route the packet. > > The main thing was just that you will not get any sensible numbers from > the lookup measurement unless you have made sure that the population of > the table has finished first. Otherwise you'll be measuring the time to > look up nonexisting stuff, and for that most storage methods will do > equally well. > But since gen_server handles messages in a FIFO manner, all inserts will be processed before the lookups. The only problem is that the first lookup will have to wait for all inserts to finish. So the time for lookups will include the time for the inserts to finish, but there will not be a lot of lookups before the inserts have finished. /Anders > /Richard > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From joelr1 Thu Oct 9 16:09:21 2008 From: joelr1 (Joel Reymont) Date: Thu, 9 Oct 2008 15:09:21 +0100 Subject: [erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names In-Reply-To: <48EDE9E0.1080606@ericsson.com> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> <48EDE9E0.1080606@ericsson.com> Message-ID: On Oct 9, 2008, at 12:24 PM, Ulf Wiger (TN/EAB) wrote: > The only thing to think about, perhaps, is that global doesn't > scale well when you add more nodes. If you have only one node, > it's very fast indeed. Here are results for 4, 25 and 50 nodes, averages calculated thusly: populate(N) -> populate(N, 0). populate(0, Avg) -> Avg; populate(N, Avg) -> if (N rem 10000) == 0 -> io:format("Avg: ~.4. f~n", [Avg / 1000000]); true -> ok end, {T, {ok, _}} = timer:tc(map8, start, [N]), populate(N - 1, (Avg + T) / 2). It looks like process registration time doubles with the # of nodes. (master)3> map8:start_slaves(4). ... ok (master)4> map8:test(100000). ... Avg: 0.0000 Avg: 0.0017 Avg: 0.0017 Avg: 0.0016 Avg: 0.0019 Avg: 0.0016 Avg: 0.0018 Avg: 0.0016 Avg: 0.0017 Avg: 0.0016 Populate: 170.1915 Avg start: 0.0017 Lookup: 0.0857 ok (master)1> map8:start_slaves(25). ... ok (master)2> map8:test(100000). Avg: 0.0000 Avg: 0.0113 Avg: 0.0105 Avg: 0.0108 Avg: 0.0111 Avg: 0.0105 Avg: 0.0096 Avg: 0.0114 Avg: 0.0110 Avg: 0.0111 Populate: 1031.4716 Avg start: 0.0111 Lookup: 0.0875 (master)1> map8:start_slaves(50). ... ok (master)2> map8:test(100000). Avg: 0.0000 Avg: 0.0240 Avg: 0.0220 Avg: 0.0248 Avg: 0.0207 Avg: 0.0234 Avg: 0.0262 Avg: 0.0242 Avg: 0.0237 Avg: 0.0241 Populate: 2393.1143 Avg start: 0.0247 Lookup: 0.0877 ok -- wagerlabs.com From erlang Thu Oct 9 16:19:20 2008 From: erlang (Joe Armstrong) Date: Thu, 9 Oct 2008 16:19:20 +0200 Subject: [erlang-questions] Fwd: disk tests In-Reply-To: <95be1d3b0810090644j7dc7fc8es88ed4a5d17e495db@mail.gmail.com> References: <9b08084c0810090618l5226d8b0m74bcfb92026e621d@mail.gmail.com> <95be1d3b0810090644j7dc7fc8es88ed4a5d17e495db@mail.gmail.com> Message-ID: <9b08084c0810090719o40e3db3en84ab57e729a15f45@mail.gmail.com> yes yes - fool that I am - the funny thing is that it worked at all - the second clause would trigger and create a collosal list in memory .... it's been a bad day ... thanks -- /Joe On Thu, Oct 9, 2008 at 3:44 PM, Vlad Dumitrescu wrote: > Hi Joe, > > Shouldn't this > >> zero_file_seqwrite(S, Len, B, Size) when Size > Len -> > > be > > zero_file_seqwrite(S, Len, B, Size) when Size =< Len -> > > instead? > > The second version works completely fine. > > regards, > Vlad > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From vychodil.hynek Thu Oct 9 16:30:31 2008 From: vychodil.hynek (Hynek Vychodil) Date: Thu, 9 Oct 2008 16:30:31 +0200 Subject: [erlang-questions] Fwd: disk tests In-Reply-To: <4d08db370810090724g61770b13kfb5ab08a0cc349ec@mail.gmail.com> References: <9b08084c0810090618l5226d8b0m74bcfb92026e621d@mail.gmail.com> <95be1d3b0810090644j7dc7fc8es88ed4a5d17e495db@mail.gmail.com> <4d08db370810090724g61770b13kfb5ab08a0cc349ec@mail.gmail.com> Message-ID: <20081009143032.3327624022@relay.gooddata.com> On Thu, Oct 9, 2008 at 4:24 PM, Hynek Vychodil wrote: > It will work also with > > zero_file_seqwrite(S, Len, B, Size) when Size < Len -> > > but I think better will be > > zero_file_seqwrite(Handler, Size, Block, BlockSize) when BlockSize < Size > -> > > and all comes clear. > > zero_file_seqwrite(_, 0, _, _) -> ok; > zero_file_seqwrite(Handler, Size, Block, BlockSize) when BlockSize < Size > -> > oh mistake, there should be BlockSize= > file:write(Handler, [Block]), > zero_file_seqwrite(Handler, Size-BlockSize, Block, BlockSize); > zero_file_seqwrite(Handler, Size, _, _) -> > Block = list_to_binary(duplicate(Size, 0)), > file:write(Handler, [Block]). > > On Thu, Oct 9, 2008 at 3:44 PM, Vlad Dumitrescu wrote: > >> Hi Joe, >> >> Shouldn't this >> >> > zero_file_seqwrite(S, Len, B, Size) when Size > Len -> >> >> be >> >> zero_file_seqwrite(S, Len, B, Size) when Size =< Len -> >> >> instead? >> >> The second version works completely fine. >> >> regards, >> Vlad >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions >> http://www.erlang.org/mailman/listinfo/erlang-questions >> > > > > -- > --Hynek (Pichi) Vychodil > -- --Hynek (Pichi) Vychodil -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/d55f51d6/attachment.html From richardc Thu Oct 9 17:58:37 2008 From: richardc (Richard Carlsson) Date: Thu, 09 Oct 2008 17:58:37 +0200 Subject: [erlang-questions] The trouble with measurements (was: Benchmarking Erlang: ...) In-Reply-To: References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> <48EDF66D.9010101@it.uu.se> <48EE096F.6090307@it.uu.se> Message-ID: <48EE2A2D.7000800@it.uu.se> Anders Nygren wrote: > But since gen_server handles messages in a FIFO manner, all inserts > will be processed before the lookups. The only problem is that the > first lookup will have to wait for all inserts to finish. So the time > for lookups will include the time for the inserts to finish, but > there will not be a lot of lookups before the inserts have finished. The major problem with benchmarks, I have to say again, is to know what is actually being measured. I thought I knew what was going on, but Anders' comment here made me sit up and think "of course he's right!" followed by "but how could that possibly fit in with what I'm seeing??" because what I was seeing was that for large N, the results from test(N) came in long before all the messages were processed by the gen_server. The explanation turned out to be complicated. It was a dark and stormy night... First, this doesn't happen as easily without SMP (and since smp is on by default these days, that was what I was using - and Joel too, I assume). Without SMP, there is a single scheduler which time-slices all the ready Erlang processes. A sender process, which does a large number (30000+) of gen_server:cast() (asynchronous messages to the server), will not be able to dispatch all of these before the gen_server process is swapped in instead and starts handling the messages. But with SMP, a sender can happily fill upp the server mailbox with tens of thousands of messages and then proceed to doing gen_server:call() instead. Second, Joel had not specified a timeout for his gen_server:call(). This means that it uses the default, which happens to be five seconds. Now, you may remember from Joel's numbers what the lookup times for large N were all very close to... So, with SMP, and sufficiently large N, the test process very quickly dispatched all its casts to ADD elements to the table, and the poor gen_server had barely started to process them, when the test process entered the first gen_server:call() to do a LOOKUP. Five seconds passed, and the call timed out (still long before the server was anywhere near getting through all the ADDs). This threw an exception, which immediately quit the lookup(Pid, N) loop after the first call. So why didn't anyone notice the timeout? Well, because of timer:tc(), of course, which runs the call within a catch! So, what the timer really measured for the lookup loop, was the time for the first gen_server:call to time out, namely, five seconds. /Richard From erlang-questions_efine Thu Oct 9 18:53:52 2008 From: erlang-questions_efine (Edwin Fine) Date: Thu, 9 Oct 2008 12:53:52 -0400 Subject: [erlang-questions] [enhancement] string:split/2 In-Reply-To: <781bce43-97e9-48fb-bba2-0ce230f2011a@t39g2000prh.googlegroups.com> References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> <34A27838-5CBA-425D-97A1-C2D2CF6F5456@cs.otago.ac.nz> <6c2563b20810082354u34372510n1fb4e1d23d777c23@mail.gmail.com> <781bce43-97e9-48fb-bba2-0ce230f2011a@t39g2000prh.googlegroups.com> Message-ID: <6c2563b20810090953n1b0c7672v17ceb84cbb59a1fd@mail.gmail.com> > > > Do you mean that string:split should be the _inverse_ of string:join? > > http://en.wikipedia.org/wiki/Inverse_function Yes, that's it. Thanks. I just wish there was a more impressive-sounding word like idempotent :) > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/08d1f2ef/attachment.html From joelr1 Thu Oct 9 19:18:39 2008 From: joelr1 (Joel Reymont) Date: Thu, 9 Oct 2008 18:18:39 +0100 Subject: [erlang-questions] The trouble with measurements (was: Benchmarking Erlang: ...) In-Reply-To: <48EE2A2D.7000800@it.uu.se> References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> <48EDF66D.9010101@it.uu.se> <48EE096F.6090307@it.uu.se> <48EE2A2D.7000800@it.uu.se> Message-ID: On Oct 9, 2008, at 4:58 PM, Richard Carlsson wrote: > So why didn't anyone notice the timeout? Well, because of timer:tc(), > of course, which runs the call within a catch! So, what the timer > really > measured for the lookup loop, was the time for the first > gen_server:call > to time out, namely, five seconds. Ouch! It works properly with call instead of cast, though, do I understand you correctly? -- wagerlabs.com From stonecypher Thu Oct 9 20:32:17 2008 From: stonecypher (John Haugeland) Date: Thu, 9 Oct 2008 12:32:17 -0600 Subject: [erlang-questions] erlang-questions Digest, Vol 17, Issue 41 In-Reply-To: <8f24f4b10810091131n7590f33aw20ae6da138a7e642@mail.gmail.com> References: <8f24f4b10810091131n7590f33aw20ae6da138a7e642@mail.gmail.com> Message-ID: <8f24f4b10810091132s74eb779cuc21ad7c93fae72f2@mail.gmail.com> > function get_card_id( { ThisBack, ThisFace, ThisSuit } ) -> > Er, obviously no function. Sorry, I've been working in PHP all morning. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/2eb84dab/attachment.html From stonecypher Thu Oct 9 20:31:07 2008 From: stonecypher (John Haugeland) Date: Thu, 9 Oct 2008 12:31:07 -0600 Subject: [erlang-questions] erlang-questions Digest, Vol 17, Issue 41 In-Reply-To: References: Message-ID: <8f24f4b10810091131n7590f33aw20ae6da138a7e642@mail.gmail.com> > > Date: Wed, 8 Oct 2008 17:01:25 +0100 > From: Joel Reymont > Subject: [erlang-questions] pid to integer and back > To: Erlang Questions > Message-ID: > Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes > > Is there a safe and efficient way to convert pid to integer and back? > > I'm assigning each running poker game an integer id. I store this id > into every outgoing packet so there's no database lookup. > > I use the id to lookup the game process for every incoming packet, > though. This is proving to be extremely inefficient, even with dirty > mnesia reads. > > I actually repeat the above for every player, so there's twice the > overhead. Is there a way to avoid it? > > This would only apply to running games and connected players so this > would be a temporary integer, valid while the process is alive. There are three general approaches to this. 1) You can pack any known integer ranges into another integer through radix multiplication. You know, for example, that you can store four decks of cards { redback, 6, hearts } in an octet by skipping ranges up to fill: -define(Suits, [hearts,clubs,spades,diamonds]). -define(Faces, [ace,2,3,4,5,6,7,8,9,10,jack,queen,king]). -define(Backs, [red,blue,green,black]). function get_card_id( { ThisBack, ThisFace, ThisSuit } ) -> SuitRadix = length(?Suits), FaceRadix = length(?Faces), ThisSuit + (ThisFace * SuitRadix) + (ThisBack * (SuitRadix*FaceRadix)). So, if you can find documentation of the maximum range of the three integers in a PID, you can just compose them this way. 2) You can keep a lookup process somewhere, and just dole out integer handles. 3) You can notice that local PIDs already only eat one word, and quit playing translation games, because they're unnecessary. (reference: http://www.erlang.org/doc/efficiency_guide/advanced.html ) The real question you should be asking yourself, in my opinion, is why you're that worried about a few bytes, and why you're trying to represent it as an integer in the first place. In most cases where people say "I need to reduce their size because there are so many they're getting out of control", it's quite common to be able to reduce the count of IDs, rather than the size of their representation. For example, if each of your player processes has a handle to each other player process, spin up a process for a given match instead, and give the player processes a hook to that and nothing else. Bang: 7/8 or so savings on PID space, and probably a significant speed increase despite the extra messaging, since you're going to get so many more correct branch predictions and cache wins. Granted, you probably aren't making a mistake that basic, and I haven't actually looked at your code, but it's an example that's clear enough to get me out of extra explanation. Micro-optimization is almost never the right way to push back machine limits. Consider working on your approach instead. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/dbeaeb9f/attachment.html From stonecypher Thu Oct 9 21:08:42 2008 From: stonecypher (John Haugeland) Date: Thu, 9 Oct 2008 13:08:42 -0600 Subject: [erlang-questions] erlang-questions Digest, Vol 17, Issue 49 In-Reply-To: References: Message-ID: <8f24f4b10810091208n56d81cf5ibdb618d44f69c2bc@mail.gmail.com> > > The hint is that your numbers _should_ scale at least linearly with > > the number of elements, > > Shouldn't lookup be O(log n)? For trees, yes. For hashes, no, amortized O(1). Which is, incidentally, why he probably shouldn't use trees. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/b212e7ec/attachment.html From stonecypher Thu Oct 9 21:03:15 2008 From: stonecypher (John Haugeland) Date: Thu, 9 Oct 2008 13:03:15 -0600 Subject: [erlang-questions] erlang-questions Digest, Vol 17, Issue 45 In-Reply-To: References: Message-ID: <8f24f4b10810091203i6eeb60f5q1b6bdaa483abea79@mail.gmail.com> > I agree that there should be an operation that is > the converse of string:join/2. It's scutil:explode(). See http://scutil.com/ . -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/56f7b311/attachment.html From erlang-questions_efine Thu Oct 9 21:52:09 2008 From: erlang-questions_efine (Edwin Fine) Date: Thu, 9 Oct 2008 15:52:09 -0400 Subject: [erlang-questions] erlang-questions Digest, Vol 17, Issue 45 In-Reply-To: <8f24f4b10810091203i6eeb60f5q1b6bdaa483abea79@mail.gmail.com> References: <8f24f4b10810091203i6eeb60f5q1b6bdaa483abea79@mail.gmail.com> Message-ID: <6c2563b20810091252l199969a3v2d82a5d9f87e0e91@mail.gmail.com> 2008/10/9 John Haugeland > > I agree that there should be an operation that is > > the converse of string:join/2. > > It's scutil:explode(). See http://scutil.com/ . > Maybe I'm just being a bit of an idealist here, but if there is an operation, string:join, I'd really, really, like its inverse operation also to be in the string module, namely, string:split. It's the symmetry. Especially since there's no earthly reason I can see that string:split should be (or have been) omitted. I suppose they could rid of string:join and we could all use scutil:explode (and I presume its inverse, scutil:implode?). But then that's another module/application I need which is not part of the standard release. > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/bc70b784/attachment.html From richardc Thu Oct 9 22:08:24 2008 From: richardc (Richard Carlsson) Date: Thu, 09 Oct 2008 22:08:24 +0200 Subject: [erlang-questions] The trouble with measurements In-Reply-To: References: <35FA1D83-B63F-4691-AA81-7129BC3BC5F9@gmail.com> <48EDF66D.9010101@it.uu.se> <48EE096F.6090307@it.uu.se> <48EE2A2D.7000800@it.uu.se> Message-ID: <48EE64B8.8020603@it.uu.se> Joel Reymont wrote: > > On Oct 9, 2008, at 4:58 PM, Richard Carlsson wrote: > >> So why didn't anyone notice the timeout? Well, because of timer:tc(), >> of course, which runs the call within a catch! So, what the timer really >> measured for the lookup loop, was the time for the first gen_server:call >> to time out, namely, five seconds. > > Ouch! It works properly with call instead of cast, though, do I > understand you correctly? Yes, if all the ADD requests are also done with gen_server:call(), the test process cannot run ahead of the server like it does now. /Richard From fig Thu Oct 9 22:13:02 2008 From: fig (Michael FIG) Date: Thu, 9 Oct 2008 14:13:02 -0600 (CST) Subject: [erlang-questions] ODBC truncates DATETIME results In-Reply-To: <20073882.23731223583086148.JavaMail.root@julie.marketel> Message-ID: <29952892.23751223583182465.JavaMail.root@julie.marketel> Hi, I've been using unixodbc in conjunction with tdsodbc and a Microsoft SQL Server 2000 database. With at least Erlang R11B1, I found that datetimes and smalldatetimes were being truncated, so I'd get results that looked like: > odbc:sql_query(O, "SELECT CAST('2008-09-03 14:35:12.234' AS DATETIME)"). {selected,[[]],[{"2008-09-"}]} > odbc:sql_query(O, "SELECT CAST('2008-09-03 14:35:12.234' AS SMALLDATETIME)"). {selected,[[]],[{"2008"}]} Upon further investigation, I found out that the culprit appears to be in odbcserver.c, where the size of the result columns is calculated. The driver combination I am using returns a length of 4 for SMALLDATETIME and 8 for DATETIME, which is inadequate to hold the results that are actually 23 characters in length. The attached patch corrects this issue: > odbc:sql_query(O, "SELECT CAST('2008-09-03 14:35:12.234' AS DATETIME)"). {selected,[[]],[{"2008-09-03 14:35:12.233"}]} > odbc:sql_query(O, "SELECT CAST('2008-09-03 14:35:12.234' AS SMALLDATETIME)"). {selected,[[]],[{"2008-09-03 14:35:00.000"}]} I'm not sure if it this bug still exists in Erlang R12, but I thought I should post this anyway. Hope this helps somebody out there, -- Michael FIG MarkeTel Multi-Line Dialing Systems, Ltd. Phone: (306) 359-6893 ext. 528 -------------- next part -------------- A non-text attachment was scrubbed... Name: erl-11.b.1-odbc.patch Type: application/octet-stream Size: 521 bytes Desc: not available Url : http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/88c686aa/attachment.obj From stonecypher Thu Oct 9 22:14:41 2008 From: stonecypher (John Haugeland) Date: Thu, 9 Oct 2008 14:14:41 -0600 Subject: [erlang-questions] erlang-questions Digest, Vol 17, Issue 45 In-Reply-To: <6c2563b20810091252l199969a3v2d82a5d9f87e0e91@mail.gmail.com> References: <8f24f4b10810091203i6eeb60f5q1b6bdaa483abea79@mail.gmail.com> <6c2563b20810091252l199969a3v2d82a5d9f87e0e91@mail.gmail.com> Message-ID: <8f24f4b10810091314r1586e999n999ffd972068e072@mail.gmail.com> Oh, I just wanted to point out that someone else agreed with you that a round trip matched functional converse was important, and that it was available to you. Besides, there's a ton of fun stuff in that library. If you install it, you'll use it. On Thu, Oct 9, 2008 at 1:52 PM, Edwin Fine wrote: > 2008/10/9 John Haugeland > >> > I agree that there should be an operation that is >> > the converse of string:join/2. >> >> It's scutil:explode(). See http://scutil.com/ . >> > Maybe I'm just being a bit of an idealist here, but if there is an > operation, string:join, I'd really, really, like its inverse operation also > to be in the string module, namely, string:split. It's the symmetry. > Especially since there's no earthly reason I can see that string:split > should be (or have been) omitted. > > I suppose they could rid of string:join and we could all use scutil:explode > (and I presume its inverse, scutil:implode?). But then that's another > module/application I need which is not part of the standard release. > GuaranteedVPS.com - bandwidth commitments and root starting from $12.98/mo -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/230a5e35/attachment-0001.html From joelr1 Thu Oct 9 22:38:14 2008 From: joelr1 (Joel Reymont) Date: Thu, 9 Oct 2008 21:38:14 +0100 Subject: [erlang-questions] erlang-questions Digest, Vol 17, Issue 41 In-Reply-To: <8f24f4b10810091131n7590f33aw20ae6da138a7e642@mail.gmail.com> References: <8f24f4b10810091131n7590f33aw20ae6da138a7e642@mail.gmail.com> Message-ID: On Oct 9, 2008, at 7:31 PM, John Haugeland wrote: >> For example, if each of your player processes has a handle to each >> other > player process, spin up a process for a given match instead, and > give the > player processes a hook to that and nothing else. How does this work? Can you elaborate a bit? > Bang: 7/8 or so savings > on PID space, and probably a significant speed increase despite the > extra > messaging, since you're going to get so many more correct branch > predictions > and cache wins. And how do you measure cache wins and branch predictions with Erlang? Thanks, Joel -- wagerlabs.com From oscar Thu Oct 9 22:43:43 2008 From: oscar (=?utf-8?Q?Oscar_Hellstr=C3=B6m?=) Date: Thu, 9 Oct 2008 21:43:43 +0100 (BST) Subject: [erlang-questions] Adding simple process to supervisor? In-Reply-To: <24398926.11601223584825347.JavaMail.root@zimbra> Message-ID: <28655359.11621223585023526.JavaMail.root@zimbra> Hi Bengt, What I usually do is just to spawn a reader process from the gen_server and link to it. Then depending on if the gen_server should die with errors in the reader process or not I sometimes traps exits in the gen_server. Most of the time you want to restart the gen_server to open a new socket if the reader dies anyway. IMHO, there are too many issues with trying to get a process that does blocking calls to exist under a supervisor and this kind of process is typically very simple (read small room for errors) as well. Another approach is to use proc_lib to create a "special process" which uses {active, once} for the socket, to get away from doing blocking calls. ----- Original Message ----- From: "Bengt Kleberg" To: "erlang-questions" Sent: Thursday, 9 October, 2008 12:03:27 AM GMT -08:00 US/Canada Pacific Subject: [erlang-questions] Adding simple process to supervisor? Greetings, I have a gen_server which is supervised according to OTP rules. Now I want to add a simple process that will read from a TCP port and send the incoming data to the gen_server. I could spawn_link this process from the gen_server and restart it if it dies. However, since I have a supervisor it seems more logical to just add the process there, as a rest_for_one. There is the alternative of using a supervisor_bridge, but that seems more complex than using the gen_server. It seems as if I just design my process according to the OTP rules I will not need to use a supervisor_bridge. What are those rules? The only suggestions I have found are: 1 Module:start_link/1 => {ok, Pid} 2 Module:terminate/2 => ok The child specification returned by the init/1 call-back in a supervisor mentions the value for Modules if we have a gen_server, gen_fsm or gen_event. What could be used for a simple process? But how do I add a simple process to the supervisor? It seems overkill to masquerade it as a get_fsm or similar. Since it is not called from erlang it is not a gen_server. Since it does not have state it is not a gen_fsm. No events are handled. bengt _______________________________________________ erlang-questions mailing list erlang-questions http://www.erlang.org/mailman/listinfo/erlang-questions -- Oscar Hellstr?m, oscar Phone: +44 (0)798 45 44 773 Mobile: +44 (0)207 65 50 337 Web: http://www.erlang-consulting.com From rvirding Thu Oct 9 23:47:50 2008 From: rvirding (Robert Virding) Date: Thu, 9 Oct 2008 23:47:50 +0200 Subject: [erlang-questions] write the ant simulation in Erlang? In-Reply-To: <859e91e70810082146k3457bd2evc813a51beda59989@mail.gmail.com> References: <859e91e70810081456w244b1c9dh74e108325ae4135c@mail.gmail.com> <7D2420AE-BA6D-4EE4-85DD-CCB6C1723DBE@cs.otago.ac.nz> <859e91e70810082144v52c0998bi140a6116c67cf12a@mail.gmail.com> <859e91e70810082146k3457bd2evc813a51beda59989@mail.gmail.com> Message-ID: <3dbc6d1c0810091447ye7fbc56j9d7ee5f322dd1854@mail.gmail.com> I haven't really checked the Clojure code that closely but it seems like a reasonable problem. Do you know if it "turn based" or do the all the ants just move after their own clocks in a parallel way? A first approximation would be to have one process per ant and one for the world. The only problem would be handling atomic look-at-the-immediate-world-around-me-and-make-a-move. The really difficult bit is displaying it. :-) Robert 2008/10/9 Brian Zhou > Let me try to reverse engineer some kind of spec: > > * On a world of 80x80 cells, there are 49 ants, and 35 scattered cells > with food. > * Initially the ants are in their home, a square from (20, 20) to (26, > 26), facing random directions. > > * An ant can move ahead, turn 45 degree left, or 45 degree right, every > 40ms. > * Ant should not move ahead if there is another ant in the ahead cell. > * Whenever ant make a move, it leaves a pheromone trail by increment > pheromone amount by 1.0 in the previous cell. > > * For an ant without food, > ** If ahead is not home, and there is food ahead, move ahead, take > food and turn around; > ** Among cells that are ahead, ahead-left (45 degree), ahead-right (45 > degree), turn/move to the one with the most (if (contain-food?) 1 0) + > pheromone score, if all equal, turn/move randomly; > > * For an ant with food, > ** If ahead is home, move ahead, drop food and turn around; > ** Among cells that are ahead, ahead-left (45 degree), ahead-right (45 > degree), turn/move to the one with the most (if (at-home?) 1 0) + > pheromone score, if all equal, turn/move randomly; > > * Every 1 second, the pheromone in all cells evaporate to 99% of the > previous amount; > > * If a graphical animation is provided, the animation is refreshed every > 100ms. > > * Hard-coded numbers are used above to make description easier. They > are actually adjustable. > > ;dimensions of square world > (def dim 80) > ;number of ants = nants-sqrt^2 > (def nants-sqrt 7) > ;number of places with food > (def food-places 35) > ;range of amount of food at a place > (def food-range 100) > ;evaporation rate > (def evap-rate 0.99) > > (def animation-sleep-ms 100) > (def ant-sleep-ms 40) > (def evap-sleep-ms 1000) > > Anyone feel free to correct me if my understanding is not right. > > -Brian > > On Wed, Oct 8, 2008 at 7:46 PM, Richard O'Keefe wrote: > > Bearing in mind that it really isn't practical > > for someone in NZ to watch videos over the international net, > > can you tell me what the ant simulation problem is? > > > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/541e0e04/attachment.html From rvirding Thu Oct 9 23:48:42 2008 From: rvirding (Robert Virding) Date: Thu, 9 Oct 2008 23:48:42 +0200 Subject: [erlang-questions] Article on Erlang in ACM Queue In-Reply-To: <200810090600.m9960KTF054979@krumkake.jetcafe.org> References: <48ED943A.80801@berabera.info> <200810090600.m9960KTF054979@krumkake.jetcafe.org> Message-ID: <3dbc6d1c0810091448v60bdd5c1of474f708fc1638be@mail.gmail.com> I agree with Romain, good article. Robert 2008/10/9 Jim Larson > In message <48ED943A.80801> you write: > >Jim Larson has written an article entitled "Erlang for Concurrent > >Programming", published in the latest ACM Queue: > >http://mags.acm.org/queue/200809/ > > Thanks to Romain for some great feedback on an early draft! > > Jim > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/318a0a2a/attachment.html From stonecypher Thu Oct 9 23:53:31 2008 From: stonecypher (John Haugeland) Date: Thu, 9 Oct 2008 15:53:31 -0600 Subject: [erlang-questions] erlang-questions Digest, Vol 17, Issue 41 In-Reply-To: References: <8f24f4b10810091131n7590f33aw20ae6da138a7e642@mail.gmail.com> Message-ID: <8f24f4b10810091453l610b3528w6145a42948aad9b@mail.gmail.com> > > For example, if each of your player processes has a handle to each other >>> >> player process, spin up a process for a given match instead, and give the >> player processes a hook to that and nothing else. >> > > How does this work? Can you elaborate a bit? Every mailing list needs ascii art! If it used to be A---B /|\ /|\ C-+-*-+-D (plus connections I can't draw \|/ \|/ from A-D, B-C, D-E, C-F) E---F Then change it to Z /|\ // \\ / | | \ /\ | | /\ A B C D E F Instead of (6*5)=30 pids, you're now tracking (6*1)+6=12 pids. The savings goes up the larger the games get, because in the old fully connected network you need N*(N-1) connections per game, whereas in the new network you need 2N connections per game, and exponential vs linear growth, and rada rada rada. > > Bang: 7/8 or so savings >> on PID space, and probably a significant speed increase despite the extra >> messaging, since you're going to get so many more correct branch >> predictions >> and cache wins. >> > > And how do you measure cache wins and branch predictions with Erlang? Ancient wisdom. When you've been programming 20+ years, you can smell what's going to work and what isn't. And, I know, for someone who says "intuition is worthless, profile it" as much as I do, that's kind of hypocritical in the way that the ocean is kind of wet, but I haven't really taken the time to learn Erlang's profiling situation yet, so it's the best I've got. But, I mean, when you drop the size of a block of data by 80-85%, you're just going to keep a lot more of it in cache, and when the data has stronger locality, it's more likely to get a good branch prediction. That's just the nature of modern branch prediction algorithms. There's a fascinating (if somewhat poorly written) discussion of these issues in the original Judy Tree papers by that guy from Hewlett Packard. - John -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/847ec076/attachment.html From stonecypher Fri Oct 10 00:29:35 2008 From: stonecypher (John Haugeland) Date: Thu, 9 Oct 2008 16:29:35 -0600 Subject: [erlang-questions] erlang-questions Digest, Vol 17, Issue 41 In-Reply-To: <20081009222447.GA19797@contorpis.lisalinda.com> References: <8f24f4b10810091131n7590f33aw20ae6da138a7e642@mail.gmail.com> <8f24f4b10810091453l610b3528w6145a42948aad9b@mail.gmail.com> <20081009222447.GA19797@contorpis.lisalinda.com> Message-ID: <8f24f4b10810091529w376de405xb66c2cf16642364e@mail.gmail.com> > > > ... in the old fully connected network > > you need N*(N-1) connections per game, whereas in the new network you > need > > 2N connections per game, and exponential vs linear growth, and ... > > N*(N-1) isn't exponential. > > Matt I'd check that math, if I were you. Try actually plotting some values, then ask yourself what the difference is between n**2, n*n, and n*(n-1). You might as well suggest that O(a*b) is linear. If its dominating term governing growth rate is a non-1 exponent, as it is in this case, it's exponential growth. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/79467d21/attachment-0001.html From gbulmer Fri Oct 10 01:03:44 2008 From: gbulmer (G Bulmer) Date: Fri, 10 Oct 2008 00:03:44 +0100 Subject: [erlang-questions] Interesting: "Squeak VM adapted to run on Tilera" Message-ID: Folks, I thought some might be interested in this ... Sam S. Adams and David Ungar (Self) have adapted the Squeak VM to run on 56 of the 64 cores on the Tilera64 processor family. "Exploring Massively Multicore Programming Models: Introducing the Renaissance ER Project" http://domino.watson.ibm.com/comm/research.nsf/pages/r.plansoft.seminars.html Mentioned by Sam Adams here: http://wiki.squeak.org/squeak/1107 G Bulmer From matthias Fri Oct 10 00:24:47 2008 From: matthias (Matthias Lang) Date: Fri, 10 Oct 2008 00:24:47 +0200 Subject: [erlang-questions] erlang-questions Digest, Vol 17, Issue 41 In-Reply-To: <8f24f4b10810091453l610b3528w6145a42948aad9b@mail.gmail.com> References: <8f24f4b10810091131n7590f33aw20ae6da138a7e642@mail.gmail.com> <8f24f4b10810091453l610b3528w6145a42948aad9b@mail.gmail.com> Message-ID: <20081009222447.GA19797@contorpis.lisalinda.com> On Thursday, October 09, John Haugeland wrote: > ... in the old fully connected network > you need N*(N-1) connections per game, whereas in the new network you need > 2N connections per game, and exponential vs linear growth, and ... N*(N-1) isn't exponential. Matt > Ancient wisdom. When you've been programming 20+ years, you smell From ok Fri Oct 10 01:21:44 2008 From: ok (Richard O'Keefe) Date: Fri, 10 Oct 2008 12:21:44 +1300 Subject: [erlang-questions] [enhancement] string:split/2 In-Reply-To: <6c2563b20810082343j255330ccp396cf4f8da0d2fe4@mail.gmail.com> References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> <6c2563b20810082343j255330ccp396cf4f8da0d2fe4@mail.gmail.com> Message-ID: <330AAA17-394B-44D0-9E09-7CEE4B6BF9C9@cs.otago.ac.nz> On 9 Oct 2008, at 7:43 pm, Edwin Fine wrote: > I'm assuming you are providing this code as an "executable > requirements document." I was rather hoping that it could be > implemented as a BIF. > I'll have to study your code below so I can learn some "fast and > fancy" Erlang! Well, no. I was providing the code as a first draft of what could be dropped into string.erl. I see no reason why it should be a BIF, if by that you mean something implemented in C. If the performance of unjoining should be a bottleneck in some program, after getting over my astonishment I would recommend unrolling. For example, > unjoin0([C|Cs]) -> > [[C] | unjoin0(Cs)]; > unjoin0([]) -> > []. would become unjoin0([A,B,C,D|S]) -> [[A],[B],[C],[D] | unjoin0(S); unjoin0([A,B,C]) -> [[A],[B],[C]]; unjoin0([A,B]) -> [[A],[B]]; unjoin0([A]) -> [[A]]; unjoin0([]) -> []. That plus HiPE can often do surprisingly well. But this is something to do AFTER measurement! From ok Fri Oct 10 01:51:07 2008 From: ok (Richard O'Keefe) Date: Fri, 10 Oct 2008 12:51:07 +1300 Subject: [erlang-questions] erlang-questions Digest, Vol 17, Issue 45 In-Reply-To: <8f24f4b10810091314r1586e999n999ffd972068e072@mail.gmail.com> References: <8f24f4b10810091203i6eeb60f5q1b6bdaa483abea79@mail.gmail.com> <6c2563b20810091252l199969a3v2d82a5d9f87e0e91@mail.gmail.com> <8f24f4b10810091314r1586e999n999ffd972068e072@mail.gmail.com> Message-ID: <61EC12E1-6393-4427-846D-8B5DDC12B4D3@cs.otago.ac.nz> I note that "explode" has historically meant "to break a string (or equivalent) into a list of its single-character elements", which is not all that split/unjoin does. Some of the names in the 'lists' module were copied from Haskell. It's a pity that Haskell's "splitAt" was copied as "split". I dare say Ruby and PHP (?) got the name 'split' from Perl, which got it from 'AWK', where a *regular expression* controls the splitting. This is the other reason for preferring to call the operation 'unjoin': anyone familiar with "split" in AWK, Perl, &c will expect string:split/2 to take a regular expression parameter, and this one DOESN'T. There is, or should be, a regular pattern words <-> unwords lines <-> unlines unjoin <-> join Oh well, sort of regular... When I clicked on the Documentation link on the scutil page, I got to some sort of Wiki thingie, with no documentation that I could see. From ok Fri Oct 10 01:54:23 2008 From: ok (Richard O'Keefe) Date: Fri, 10 Oct 2008 12:54:23 +1300 Subject: [erlang-questions] write the ant simulation in Erlang? In-Reply-To: <3dbc6d1c0810091447ye7fbc56j9d7ee5f322dd1854@mail.gmail.com> References: <859e91e70810081456w244b1c9dh74e108325ae4135c@mail.gmail.com> <7D2420AE-BA6D-4EE4-85DD-CCB6C1723DBE@cs.otago.ac.nz> <859e91e70810082144v52c0998bi140a6116c67cf12a@mail.gmail.com> <859e91e70810082146k3457bd2evc813a51beda59989@mail.gmail.com> <3dbc6d1c0810091447ye7fbc56j9d7ee5f322dd1854@mail.gmail.com> Message-ID: On 10 Oct 2008, at 10:47 am, Robert Virding wrote: > A first approximation would be to have one process per ant and one > for the world. The only problem would be handling atomic look-at-the- > immediate-world-around-me-and-make-a-move. Thinking idly about this last night, I wondered whether the look at the world bit *should* be atomic. Real ants don't lock the real world, and while an ant is looking at one square, something _could_ move into a square it can't see. I was wondering about dividing the world into patches. From jeffm Fri Oct 10 02:51:38 2008 From: jeffm (jm) Date: Fri, 10 Oct 2008 11:51:38 +1100 Subject: [erlang-questions] write the ant simulation in Erlang? In-Reply-To: References: <859e91e70810081456w244b1c9dh74e108325ae4135c@mail.gmail.com> <7D2420AE-BA6D-4EE4-85DD-CCB6C1723DBE@cs.otago.ac.nz> <859e91e70810082144v52c0998bi140a6116c67cf12a@mail.gmail.com> <859e91e70810082146k3457bd2evc813a51beda59989@mail.gmail.com> <3dbc6d1c0810091447ye7fbc56j9d7ee5f322dd1854@mail.gmail.com> Message-ID: <48EEA71A.8010104@ghostgun.com> Richard O'Keefe wrote: > I was wondering about dividing the world into patches. > > This was my first reaction when seeing a description of the problem. To create a process for each square and then use a naming convention for the processes, eg world_x_y where x, y are the co-ordinates of the square. For an 80 x 80 world this would be 6400 processes just for the world plus 49 ant processes which I thought might be a bit of an over kill. I was also concerned that the process name look up may be a bottle neck. The API for the square processes might be something along the lines of * look return the status of the square. Presents of ant, food, etc. * take move to this tile. Returns success or failure. The ant would look at the square to see if it was empty and if there was any food. If the square was chosen as the next location the ant would attempt to move there by attempting to take the square which could fail if another ant had taken the square in the interim. In which case it would look for a new square, otherwise it would up date its own status to reflect the new location. Jeff. From rvirding Fri Oct 10 02:57:07 2008 From: rvirding (Robert Virding) Date: Fri, 10 Oct 2008 02:57:07 +0200 Subject: [erlang-questions] write the ant simulation in Erlang? In-Reply-To: References: <859e91e70810081456w244b1c9dh74e108325ae4135c@mail.gmail.com> <7D2420AE-BA6D-4EE4-85DD-CCB6C1723DBE@cs.otago.ac.nz> <859e91e70810082144v52c0998bi140a6116c67cf12a@mail.gmail.com> <859e91e70810082146k3457bd2evc813a51beda59989@mail.gmail.com> <3dbc6d1c0810091447ye7fbc56j9d7ee5f322dd1854@mail.gmail.com> Message-ID: <3dbc6d1c0810091757y7acee41r63464976c1eee0ba@mail.gmail.com> 2008/10/10 Richard O'Keefe > > On 10 Oct 2008, at 10:47 am, Robert Virding wrote: > >> A first approximation would be to have one process per ant and one for the >> world. The only problem would be handling atomic >> look-at-the-immediate-world-around-me-and-make-a-move. >> > > Thinking idly about this last night, I wondered whether > the look at the world bit *should* be atomic. Real ants > don't lock the real world, and while an ant is looking at > one square, something _could_ move into a square it can't > see. This was to get around the problem of checking if a cell was free before moving into and then finding the cell has been taken. The immediate world is one cell left, center, right, so it is very immediate. The "spec" stated only one ant per cell. Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081010/e8970b50/attachment.html From ok Fri Oct 10 03:08:29 2008 From: ok (Richard O'Keefe) Date: Fri, 10 Oct 2008 14:08:29 +1300 Subject: [erlang-questions] write the ant simulation in Erlang? In-Reply-To: <3dbc6d1c0810091757y7acee41r63464976c1eee0ba@mail.gmail.com> References: <859e91e70810081456w244b1c9dh74e108325ae4135c@mail.gmail.com> <7D2420AE-BA6D-4EE4-85DD-CCB6C1723DBE@cs.otago.ac.nz> <859e91e70810082144v52c0998bi140a6116c67cf12a@mail.gmail.com> <859e91e70810082146k3457bd2evc813a51beda59989@mail.gmail.com> <3dbc6d1c0810091447ye7fbc56j9d7ee5f322dd1854@mail.gmail.com> <3dbc6d1c0810091757y7acee41r63464976c1eee0ba@mail.gmail.com> Message-ID: <07630C85-CE8E-475B-8E01-B44EF3FFFC09@cs.otago.ac.nz> On 10 Oct 2008, at 1:57 pm, Robert Virding wrote: > This was to get around the problem of checking if a cell was free > before moving into and then finding the cell has been taken. That was understood. > The immediate world is one cell left, center, right, so it is very > immediate. The "spec" stated only one ant per cell. It *happened* to be very immediate. What about a protocol like this: check each relevant square choose where to go ask the world to move you if it refuses, try again with locking. The old "locks are usually not contended" idea. I think one process per cell of the world may make sense. From corticalcomputer Fri Oct 10 03:08:36 2008 From: corticalcomputer (G.S.) Date: Thu, 9 Oct 2008 18:08:36 -0700 Subject: [erlang-questions] Are there any companies that hire Erlangers? Message-ID: <2a67d3ff0810091808x2c4be63dpbe1ef8f79654593c@mail.gmail.com> Hello All, I have yet to find a company that programs using Erlang, and I'd really like to work for one. Am I looking in the wrong place, do any of you know a company that uses Erlang as the main language? -Gene -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/428a09b5/attachment.html From dbarker Fri Oct 10 02:18:49 2008 From: dbarker (Deryk Barker) Date: Thu, 09 Oct 2008 17:18:49 -0700 Subject: [erlang-questions] erlang-questions Digest, Vol 17, Issue 41 In-Reply-To: <8f24f4b10810091529w376de405xb66c2cf16642364e@mail.gmail.com> References: <8f24f4b10810091131n7590f33aw20ae6da138a7e642@mail.gmail.com> <8f24f4b10810091453l610b3528w6145a42948aad9b@mail.gmail.com> <20081009222447.GA19797@contorpis.lisalinda.com> <8f24f4b10810091529w376de405xb66c2cf16642364e@mail.gmail.com> Message-ID: <48EE9F69.6020004@camosun.bc.ca> John Haugeland wrote: > > > ... in the old fully connected network > > you need N*(N-1) connections per game, whereas in the new > network you need > > 2N connections per game, and exponential vs linear growth, and ... > > N*(N-1) isn't exponential. > > Matt > > > I'd check that math, if I were you. Try actually plotting some > values, then ask yourself what the difference is between n**2, n*n, > and n*(n-1). You might as well suggest that O(a*b) is linear. > > If its dominating term governing growth rate is a non-1 exponent, as > it is in this case, it's exponential growth. Surely it's polynomial? 2**N would be exponential. -- |Deryk Barker, Computer Science Dept. | Music does not have to be understood| |Camosun College, Victoria, BC, Canada| It has to be listened to. | |email: dbarker | | |phone: +1 250 370 4452 | Hermann Scherchen. | From ok Fri Oct 10 03:26:42 2008 From: ok (Richard O'Keefe) Date: Fri, 10 Oct 2008 14:26:42 +1300 Subject: [erlang-questions] write the ant simulation in Erlang? In-Reply-To: <48EEA71A.8010104@ghostgun.com> References: <859e91e70810081456w244b1c9dh74e108325ae4135c@mail.gmail.com> <7D2420AE-BA6D-4EE4-85DD-CCB6C1723DBE@cs.otago.ac.nz> <859e91e70810082144v52c0998bi140a6116c67cf12a@mail.gmail.com> <859e91e70810082146k3457bd2evc813a51beda59989@mail.gmail.com> <3dbc6d1c0810091447ye7fbc56j9d7ee5f322dd1854@mail.gmail.com> <48EEA71A.8010104@ghostgun.com> Message-ID: On 10 Oct 2008, at 1:51 pm, jm wrote: > This was my first reaction when seeing a description of the problem. > To > create a process for each square and then use a naming convention for > the processes, eg world_x_y where x, y are the co-ordinates of the > square. For an 80 x 80 world this would be 6400 processes just for the > world plus 49 ant processes which I thought might be a bit of an over > kill. I was also concerned that the process name look up may be a > bottle > neck. First, I was originally talking about dividing the world up into *patches*, not *cells*. In an 80x80 world, patches might be 10x10, which is only 64 patches. Second, why on earth would you *name* the patch processes? Let's now switch to cell processes, not patch processes. A cell needs to know its neighbours. element_number(nw) -> 1; element_number(n) -> 2; element_number(ne) -> 3; element_number(e) -> 4; element_number(se) -> 5; element_number(s) -> 6; element_number(sw) -> 7; element_number(w) -> 8. cell() -> cell_start({0,0,0,0,0,0,0,0}). cell_start(Neighbours) -> receive go -> cell_loop(Neighbours, 0, 0, no_ant) ; {D,N} -> cell_start(setelement( element_number(D), Neighbours, N)) end. cell_loop(Neighbours, Pheromone, Food, Ant) -> .... startup() -> create an 80 x 80 array of processes all running cell/0 using spawn_link set up all the neighbour links send each cell a !go message Something along those lines. Processes normally shouldn't *have* names, and in this problem there certainly doesn't seem to be any reason for any process to have a name, so process name lookup can't be a bottleneck. Moving is a little tricky because we need to change the state of two cells (if doing cells) or possibly two patches (if doing patches). From erlang-questions_efine Fri Oct 10 04:11:04 2008 From: erlang-questions_efine (Edwin Fine) Date: Thu, 9 Oct 2008 22:11:04 -0400 Subject: [erlang-questions] erlang-questions Digest, Vol 17, Issue 45 In-Reply-To: <61EC12E1-6393-4427-846D-8B5DDC12B4D3@cs.otago.ac.nz> References: <8f24f4b10810091203i6eeb60f5q1b6bdaa483abea79@mail.gmail.com> <6c2563b20810091252l199969a3v2d82a5d9f87e0e91@mail.gmail.com> <8f24f4b10810091314r1586e999n999ffd972068e072@mail.gmail.com> <61EC12E1-6393-4427-846D-8B5DDC12B4D3@cs.otago.ac.nz> Message-ID: <6c2563b20810091911j581553d9s1f7bcc766620c48c@mail.gmail.com> On Thu, Oct 9, 2008 at 7:51 PM, Richard O'Keefe wrote: > I note that "explode" has historically meant > "to break a string (or equivalent) into a list of its > single-character elements", > which is not all that split/unjoin does. > > Some of the names in the 'lists' module were copied > from Haskell. It's a pity that Haskell's "splitAt" > was copied as "split". > > I dare say Ruby and PHP (?) got the name 'split' > from Perl, which got it from 'AWK', where a > *regular expression* controls the splitting. I am sure they did. > > This is the other reason for preferring to call the > operation 'unjoin': anyone familiar with "split" in > AWK, Perl, &c will expect string:split/2 to take a > regular expression parameter, and this one DOESN'T. Ok, then to preserve the Principle Of Least Astonishment, let string:split accept a regular expression, which is just a string with special RE operators. If the string contains no RE operators, use an optimized special case of split (like the one you wrote) that does not use an RE engine. Get the best of both worlds. > There is, or should be, a regular pattern > words <-> unwords > lines <-> unlines > unjoin <-> join > Oh well, sort of regular... > Sorry, and no offense meant, but that's really horribly ugly. Reminds me of that sentence, "A not unblack dog chased a not unbrown rabbit across a not ungreen field." Should the opposite of down then be "undown"? Languages (well, I can vouch for two, anyway) contain many complementary words that are not syntactically constructable by adding or removing "un-". Like split and join, for example. Hard and soft. Big and small. Break and mend. Wake and sleep. > When I clicked on the Documentation link on the scutil page, > I got to some sort of Wiki thingie, with no documentation > that I could see. > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/07452563/attachment.html From erlang-questions_efine Fri Oct 10 04:32:33 2008 From: erlang-questions_efine (Edwin Fine) Date: Thu, 9 Oct 2008 22:32:33 -0400 Subject: [erlang-questions] [enhancement] string:split/2 In-Reply-To: <330AAA17-394B-44D0-9E09-7CEE4B6BF9C9@cs.otago.ac.nz> References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> <6c2563b20810082343j255330ccp396cf4f8da0d2fe4@mail.gmail.com> <330AAA17-394B-44D0-9E09-7CEE4B6BF9C9@cs.otago.ac.nz> Message-ID: <6c2563b20810091932x245481ew538675b5526e8db3@mail.gmail.com> On Thu, Oct 9, 2008 at 7:21 PM, Richard O'Keefe wrote: > > On 9 Oct 2008, at 7:43 pm, Edwin Fine wrote: > >> I'm assuming you are providing this code as an "executable requirements >> document." I was rather hoping that it could be implemented as a BIF. >> I'll have to study your code below so I can learn some "fast and fancy" >> Erlang! >> > > Well, no. I was providing the code as a first draft of what > could be dropped into string.erl. I see no reason why it should > be a BIF, if by that you mean something implemented in C. Yes, that is what I meant. > > If the performance of unjoining should be a bottleneck in some My background and experience has led me to believe that primitive operations, or functions that are likely to be heavily used, should be implemented in a low-level language like C, and not in the higher-level language. I consider string:split to be something that will be heavily used in text-processing applications (which will also become heavily used, I predict). Since string operations really need to be efficient, I wrongly assumed that the string operations were written in C and that the equivalent Erlang code would not be nearly as efficient. > program, after getting over my astonishment I would recommend > unrolling. For example, > > unjoin0([C|Cs]) -> >> [[C] | unjoin0(Cs)]; >> unjoin0([]) -> >> []. >> > > would become > > unjoin0([A,B,C,D|S]) -> [[A],[B],[C],[D] | unjoin0(S); > unjoin0([A,B,C]) -> [[A],[B],[C]]; > unjoin0([A,B]) -> [[A],[B]]; > unjoin0([A]) -> [[A]]; > unjoin0([]) -> []. > > That plus HiPE can often do surprisingly well. I'd rather ensure that the function is implemented efficiently to start off with, and not *require* HiPE to be used to get performance. One of these nights when I have some spare time, I am going to try your code out (with and without HiPE) against a 'C' or C++ version of split and join so that I can have some hard data to tell for sure one way or the other. This is how I see it: even given the increasingly fast computer architectures of today, one should do one's best not to waste processor time when performance is desired. I have seen users of interpreted, byte-code interpreted, and threaded-interpreted languages implement computationally expensive, heavily used functions in the language instead of in a low-level C library. In almost all cases where the code was not I/O bound, there was a significant penalty for writing such functions. Rewriting those functions in C/C++ often gave one or two orders of magnitude improvement. I know that the overall algorithm can make a huge difference, and that we should not waste our time with premature optimization, but at the same time we should not waste CPU time with belated pessimization. If we can predict based on experience that something (a) is likely to be heavily used and (b) will be more efficient in a lower-level language then we should implement it in said language. All the little inefficiencies can add up into a steaming great system-wide inefficiency. The death of a thousand cuts. Now, that having been said, I have not devoted time (yet) to studying the relative efficiency of Erlang-implemented operations compared to C code. Obviously in a large-scale sense, Erlang is generally efficient enough given the uses to which it has been put. On the gripping hand, the uses to which Erlang has been put are going to push its envelope as it gains more traction. It's going to be used in many more Web-related applications, which means *inter alia* much more text processing involving fiddling around with strings (excuse the unintended pun). Fiddling with strings can and does kill systems that are not designed to do that. Here's the old war story ploy. I once ported a C++ application to an IBM mainframe - which had (gasp!) a C++ compiler - and saw the mainframe get absolutely *caned* by my laptop performance-wise in many cases. Investigation at that time revealed that although the mainframe wiped out my laptop in terms of I/O speed and bandwidth, my laptop just smoked the IBM when it came to what goes on in the Web: dynamic string processing and lots of memory allocations and deallocations. IBM, seeing the writing on the wall, modified its hardware architecture, IIRC by adding special string opcodes, and improved its runtime libraries, to support more efficient string-processing and better dynamic memory handling. Now Erlang has been known to present challenges when it comes to string processing (and pattern matching and file I/O - see the WideFinder project) if the unwary don't take special steps like using binaries for efficiency, and keeping as much as possible in iolists instead of having everything flattened. We all know that Erlang was originally intended for soft real-time type applications. The way things go is that as a language proves its merits, and becomes more and more in demand because (in Erlang's case) it has a reputation for creating highly reliable and available systems, people will start pushing the envelope of its original design parameters. Reading the history of Awk is interesting in this regard; it was put to uses which the authors never dreamed of (like implementing a database - horror). Demands came in for more and better library functions. I predict the same will happen with Erlang, if it is not already happening. It is well to say that one shouldn't use one single language to do everything (and I agree with that caution), but in my experience, software managers don't like having too many languages floating about because of the recruitment, maintenance and training burden. Many developers are not as gifted as the readers of this list and find it difficult to hop between different languages. This all creates a tendency to use the primary language for as many things as possible (the old hammer and nails analogy), even if it wasn't designed for that. It is therefore probably a good idea that we don't pessimize Erlang by writing fundamental code in Erlang that arguably should be implemented as 'C' BIFs. And I am sure there will be argument :) But this is something to do AFTER measurement! > Ideally, yes, and then again, maybe not, if we strongly suspect that it's going to bite us later NOT to do it now. Here's the problem: like I wrote earlier about the death of a thousand cuts, what if there isn't a few big bottlenecks? What if the system is slow simply because it is bloated from too many unnecessary opcodes being executed in a fairly distributed pattern? Like John Haugeland (sp?) wrote earlier, sometimes 20+ years of programming experience gives one an intuitive idea regarding performance. Every little bit counts (excuse the pun). I am just generally saying that if one doesn't watch out, the system gradually bloats with new high-level code and then it's not so performant anymore. Now I will duck into the flame-proof bomb shelter. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/b78c807b/attachment.html From erlang-questions_efine Fri Oct 10 04:37:27 2008 From: erlang-questions_efine (Edwin Fine) Date: Thu, 9 Oct 2008 22:37:27 -0400 Subject: [erlang-questions] Are there any companies that hire Erlangers? In-Reply-To: <2a67d3ff0810091808x2c4be63dpbe1ef8f79654593c@mail.gmail.com> References: <2a67d3ff0810091808x2c4be63dpbe1ef8f79654593c@mail.gmail.com> Message-ID: <6c2563b20810091937u2b411cean65d972caa4d60bd9@mail.gmail.com> Not to be funny, but in which country? I mean, where are you looking? In the U.K for example, I think I know of a company or two that uses primarily Erlang (Erlang Training and Consulting is one, and I think LShift is another - http://www.lshift.net/recruitment). 2008/10/9 G.S. > Hello All, > > I have yet to find a company that programs using Erlang, and I'd really > like to work for one. Am I looking in the wrong place, do any of you know a > company that uses Erlang as the main language? > > -Gene > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/4f4ff2a4/attachment-0001.html From jeffm Fri Oct 10 04:54:46 2008 From: jeffm (jm) Date: Fri, 10 Oct 2008 13:54:46 +1100 Subject: [erlang-questions] write the ant simulation in Erlang? In-Reply-To: References: <859e91e70810081456w244b1c9dh74e108325ae4135c@mail.gmail.com> <7D2420AE-BA6D-4EE4-85DD-CCB6C1723DBE@cs.otago.ac.nz> <859e91e70810082144v52c0998bi140a6116c67cf12a@mail.gmail.com> <859e91e70810082146k3457bd2evc813a51beda59989@mail.gmail.com> <3dbc6d1c0810091447ye7fbc56j9d7ee5f322dd1854@mail.gmail.com> <48EEA71A.8010104@ghostgun.com> Message-ID: <48EEC3F6.8060101@ghostgun.com> Richard O'Keefe wrote: > > On 10 Oct 2008, at 1:51 pm, jm wrote: >> This was my first reaction when seeing a description of the problem. Read the first sentence. I was not stating it was a good idea merely sketching out an idea between doing some work. There are obviously some problems with the approach taken, but I think using a process per square (cell) or a subset of squares (patch) is a more natural approach for erlang. As this approach mantains the atomic nature of the squares and scales more easily as the cores/processes grow. > First, I was originally talking about dividing the world > up into *patches*, not *cells*. In an 80x80 world, > patches might be 10x10, which is only 64 patches. > > Second, why on earth would you *name* the patch processes? Just a simple way to find the correct process in a first cut and easier to see what is going on. You could also prime each ant with knowledge of which processes represent each square(s) or each patch/cell could contain this knowledge which is what I think your thinking. > > startup() -> > create an 80 x 80 array of processes > all running cell/0 using spawn_link > set up all the neighbour links > send each cell a !go message > > Moving is a little tricky because we need to change the > state of two cells (if doing cells) or possibly two > patches (if doing patches). Can you live with an ant occupying two squares at once? Then enter the new location first before leaving the old location. Jeff. From rec Fri Oct 10 05:17:16 2008 From: rec (Roger Critchlow) Date: Thu, 9 Oct 2008 21:17:16 -0600 Subject: [erlang-questions] write the ant simulation in Erlang? In-Reply-To: <48EEC3F6.8060101@ghostgun.com> References: <859e91e70810081456w244b1c9dh74e108325ae4135c@mail.gmail.com> <7D2420AE-BA6D-4EE4-85DD-CCB6C1723DBE@cs.otago.ac.nz> <859e91e70810082144v52c0998bi140a6116c67cf12a@mail.gmail.com> <859e91e70810082146k3457bd2evc813a51beda59989@mail.gmail.com> <3dbc6d1c0810091447ye7fbc56j9d7ee5f322dd1854@mail.gmail.com> <48EEA71A.8010104@ghostgun.com> <48EEC3F6.8060101@ghostgun.com> Message-ID: <66d1c98f0810092017n5610b482h9517935400aab383@mail.gmail.com> On Thu, Oct 9, 2008 at 8:54 PM, jm wrote: > > > > Moving is a little tricky because we need to change the > > state of two cells (if doing cells) or possibly two > > patches (if doing patches). > Can you live with an ant occupying two squares at once? Then enter the > new location first before leaving the old location. > That would break the transactional consistency that the example has in Clojure: You have a thing you want to move from one place to another, you don't want it to be in both places, and you don't want it to be no place. It would also break the graphical display of the simulation if the number of ants fluctuated from frame to frame. -- rec -- -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081009/dc9689bb/attachment.html From jeffm Fri Oct 10 05:30:52 2008 From: jeffm (jm) Date: Fri, 10 Oct 2008 14:30:52 +1100 Subject: [erlang-questions] write the ant simulation in Erlang? In-Reply-To: <66d1c98f0810092017n5610b482h9517935400aab383@mail.gmail.com> References: <859e91e70810081456w244b1c9dh74e108325ae4135c@mail.gmail.com> <7D2420AE-BA6D-4EE4-85DD-CCB6C1723DBE@cs.otago.ac.nz> <859e91e70810082144v52c0998bi140a6116c67cf12a@mail.gmail.com> <859e91e70810082146k3457bd2evc813a51beda59989@mail.gmail.com> <3dbc6d1c0810091447ye7fbc56j9d7ee5f322dd1854@mail.gmail.com> <48EEA71A.8010104@ghostgun.com> <48EEC3F6.8060101@ghostgun.com> <66d1c98f0810092017n5610b482h9517935400aab383@mail.gmail.com> Message-ID: <48EECC6C.1080808@ghostgun.com> Roger Critchlow wrote: > > That would break the transactional consistency that the example has in > Clojure: You have a thing you want to move from one place to another, > you don't want it to be in both places, and you don't want it to be no > place. > > It would also break the graphical display of the simulation if the > number of ants fluctuated from frame to frame. > What about having more states that just occupied and empty (with respect to ants)? Just thinking aloud, how about one of empty, moving, and occupied? No, that doesn't work either. How about asking the current square to move the ant to the next square? I don't think this works either though. There must be something wrong with the way I'm looking at this. Oh well, back to the day job. Jeff. From ok Fri Oct 10 05:53:41 2008 From: ok (Richard O'Keefe) Date: Fri, 10 Oct 2008 16:53:41 +1300 Subject: [erlang-questions] erlang-questions Digest, Vol 17, Issue 45 In-Reply-To: <6c2563b20810091911j581553d9s1f7bcc766620c48c@mail.gmail.com> References: <8f24f4b10810091203i6eeb60f5q1b6bdaa483abea79@mail.gmail.com> <6c2563b20810091252l199969a3v2d82a5d9f87e0e91@mail.gmail.com> <8f24f4b10810091314r1586e999n999ffd972068e072@mail.gmail.com> <61EC12E1-6393-4427-846D-8B5DDC12B4D3@cs.otago.ac.nz> <6c2563b20810091911j581553d9s1f7bcc766620c48c@mail.gmail.com> Message-ID: On 10 Oct 2008, at 3:11 pm, Edwin Fine wrote: > Ok, then to preserve the Principle Of Least Astonishment, let > string:split accept a regular expression, which is just a string > with special RE operators. If the string contains no RE operators, > use an optimized special case of split (like the one you wrote) that > does not use an RE engine. Get the best of both worlds. No, that *violates* the principle of least astonishment, Big Time! First, absolutely nothing else whatever in the 'string' module has anything to do with regular expressions. This would be highly exceptional and very confusing. Second, something that splits strings using regular expressions would be expected in the 'regexp' module, not the 'string' module. In fact, regexp:split/2 already exists. It would be rather astonishing to replicate this in the wrong module. Third, if there were a string:split/2 that used regular expressions, that would make it very incompatible with string:join/2, which doesn't. I thought we were wanting string:join(string:split(String, Sep), Sep) to give back Sep. In short, if you want something called 'split' that preserves the principle of least astonishment, use regexp:split/2. If you want an opposite of string:join/2, DON'T make it use regular expressions, and DON'T call i split/2. By the way, I have a use for string:join(reverse([Stuff|tail(reverse( string:unjoin(Thing, ".")))]), ".") so I would be very unhappy to have to write one of those string literals as "\\." and the other NOT. > > > > There is, or should be, a regular pattern > words <-> unwords > lines <-> unlines > unjoin <-> join > Oh well, sort of regular... > > Sorry, and no offense meant, but that's really horribly ugly. So you really hate it that English has "tie" and "untie", "do" and "undo", "wary" and "unwary", amongst many pairs? > Reminds me of that sentence, "A not unblack dog chased a not unbrown > rabbit across a not ungreen field." Straw man. The nasty thing about that sentence is the double negations. There is no double negation in unjoin. "unwords" and "unlines" are not my inventions, they are from the Haskell standard Prelude. > Should the opposite of down then be "undown"? Languages (well, I can > vouch for two, anyway) contain many complementary words that are not > syntactically constructable by adding or removing "un-". What of it? The words/unwords lines/unline pattern DOES exist in the language Erlang copied many of its list processing function names from. It's not my invention. Indeed, the Haskell community is as familiar with "unfold" as with "fold". In this specific context, UNdoing the effect of a list operation, "un-" is an excellent cultural fit. The fact that for example "add" and "subtract" are not related in that way really doesn't signify anything, just as the fact that there are many colours doesn't mean that black is a bad choice. > Like split and join, for example. Hard and soft. Big and small. > Break and mend. Wake and sleep. Join is also related to sever, disunite, unfasten, disconnect, unyoke, separate, put asunder, unlink, disassociate, disaffiliate, resign, detach, disengage, leave, part, divide, quit, ... Split is also related to unite, unify, connect, fragm?nt (stress shown), and another whole lot of words. It's not as if "split" and "join" were each other's _only_ relative. From ok Fri Oct 10 06:16:20 2008 From: ok (Richard O'Keefe) Date: Fri, 10 Oct 2008 17:16:20 +1300 Subject: [erlang-questions] Bug in string:to_{lower,upper}/1? Message-ID: <5EBB3A16-726D-41C7-B295-280E83161232@cs.otago.ac.nz> In string.erl we find to_lower_char(C) when is_integer(C), C >= $A, C =< $Z -> C + 32; to_lower_char(C) when is_integer(C), C >= 16#C1, C =< 16#D6 -> C + 32; to_lower_char(C) when is_integer(C), C >= 16#D8, C =< 16#DE -> C + 32; to_lower_char(C) -> C. to_upper_char(C) when is_integer(C), C >= $a, C =< $z -> C - 32; to_upper_char(C) when is_integer(C), C >= 16#E1, C =< 16#F6 -> C - 32; to_upper_char(C) when is_integer(C), C >= 16#F8, C =< 16#FE -> C - 32; to_upper_char(C) -> C. But 16#C0 is capital A with grave, which is an upper case letter that should be converted, and to_lower_char/1 does not recognise it. I think 16#C1 should be 16#C0. And 16#E0 is lower case A with grave, which is a lower case letter that should be converted, but to_upper_char/1 does not recognise it. I think 16#E1 should be 16#E0. While these functions are not export, they are the guts of to_lower/1 and to_upper/1. From ok Fri Oct 10 07:00:58 2008 From: ok (Richard O'Keefe) Date: Fri, 10 Oct 2008 18:00:58 +1300 Subject: [erlang-questions] [enhancement] string:split/2 In-Reply-To: <6c2563b20810091932x245481ew538675b5526e8db3@mail.gmail.com> References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> <6c2563b20810082343j255330ccp396cf4f8da0d2fe4@mail.gmail.com> <330AAA17-394B-44D0-9E09-7CEE4B6BF9C9@cs.otago.ac.nz> <6c2563b20810091932x245481ew538675b5526e8db3@mail.gmail.com> Message-ID: <8689C36E-B021-4300-88E1-AB66164891F6@cs.otago.ac.nz> On 10 Oct 2008, at 3:32 pm, Edwin Fine wrote: > My background and experience has led me to believe that primitive > operations, or functions that are likely to be heavily used, should > be implemented in a low-level language like C, and not in the higher- > level language. This is why, until Intergraph took it over, Quintus was the peer of Prologs. We didn't believe that. We ate our own dog food. If some aspect of our Prolog system was so slow that we were tempted to rewrite it in C, we said "oh no, our customers will find it too slow too" and improved our system. Some other companies said "we must have a fast compiler, so we'll write our compiler in C." That meant their customers found performance problems in generated code before they did. OOPS. Whether you call it split/2 or unjoin/2, it ISN'T a primitive operation. It's very easy to define in terms of other operations. And it HASN'T been heavily used, or it would already be there. > I consider string:split to be something that will be heavily used in > text-processing applications (which will also become heavily used, I > predict). I've done a lot of splitting in my time, and I must say that I have never found it to be the performance bottleneck. There's one thing I've learned over the years, and that is never to think I know where the time will go. Always measure. I've been progamming since the early 70s, and I am *still* surprised every time. > Since string operations really need to be efficient, Do they? Remind me never to use Java or Perl then. They need to be efficient *enough* not to be the bottleneck. For some applications, they might be. For some, not. Strings are almost always the wrong tool for the job. > I wrongly assumed that the string operations were written in C and > that the equivalent Erlang code would not be nearly as efficient. The 'string' library deals with strings represented as lists of integer character codes. C code _could_ be faster, but it would be hell to write. First you get your code working, then you measure it on real applications, then you improve your compiler, then you measure again, and only afterwards do you even think about putting things in C. And when you do, you think in terms of better building blocks, not in terms of doing the top level operation directly. Now this is what has already been happening slowly in Erlang. List length, reverse, and member have all migrated to C. They turn out to be very common building blocks. In 'string', instead of hacking unjoin/2, it would be best to hack the version of 'prefix' that I sent (which either returns the list after the prefix or the atom 'no'). That version can do the job of the existing 'prefix' code in 'string', but not conversely. > I'd rather ensure that the function is implemented efficiently to > start off with, and not require HiPE to be used to get performance. What is the point of worrying about the efficiency of a function when we don't even have agreement on its name? Get it right *first*. Talking about "not requir[ing] HiPE" is like saying "I demand that your C compiler produce efficient code without optimisation." Setting compiler options routinely produces more than a factor of 2 in C speed these days. (Even with the Intel C compiler, I found changing from its default options gave me a factor of 2.) Until you have *measured* the actual performance of my implementation of unjoin/2 in a real program working on real data, you have no reason to complain of its efficiency. > One of these nights when I have some spare time, I am going to try > your code out (with and without HiPE) against a 'C' or C++ version > of split and join so that I can have some hard data to tell for sure > one way or the other. What counts is the performance of the *whole* program. What might be more important in a complete program would be using binaries instead of strings. That could usefully go in C. Let's take a look at a use of the 'string' module. extract_sequences(Fmt, Need0) -> case string:chr(Fmt, $~) of 0 -> {ok,lists:reverse(Need0)}; %That's it Pos -> Fmt1 = string:substr(Fmt, Pos+1), %Skip ~ case extract_sequence(1, Fmt1, Need0) of {ok,Need1,Rest} -> extract_sequences(Rest, Need1); Error -> Error end end. The problem here is that whoever did this was thinking in a very C-like way. Suppose we had a different version of member/2, one which like its Lisp original returned a list: [] means not found, [X|_] means "found here". memq(X, [H|T]) when H =/= X -> memq(X, T); memq(_, L) -> L. Then the extract_sequences/2 function could be extract_sequences(Fmt, Need0) -> case memq($~, Fmt) of [] -> {ok, lists:reverse(Need0)} ; [_|Fmt1] -> case extract_sequence(1, Fmt1, Need0) of {ok,Need1,Rest} -> extract_sequences(Rest, Need1) ; Error -> Error end end. The original version traverses a list twice. The revised version traverses it once. In this case, coding string:substr/2 would have been the wrong way to get performance; the best way is to eliminate it entirely. Recently, I have been saying to myself "Suppose we had a rigid separation between guards and expressions, suppose we tried to completely do without 'false' and 'true' in expressions. What then?" The answer so far is "my code is the better for it. Every time." As far as I am concerned, the effort spent coding member/2 in C was effort spent on the *wrong* version of that concept. > > This is how I see it: even given the increasingly fast computer > architectures of today, one should do one's best not to waste > processor time when performance is desired. Indeed. But a programmer's primary job is to deliver working code on time and within budget. Time spent optimising functions that don't actually matter very much to the overall performance of the complete system is time wasted. Writing things in a low level language like C takes much more effort than writing them in a high level language. So you code as much as you can in your high level language and play around with it until the design settles, then you benchmark on real data, and when you know where the bottlenecks are, do you then recode in C? No, you try first to redesign the slow stuff out. (Like the extract_sequences/2 example above.) > I have seen users of interpreted, byte-code interpreted, and > threaded-interpreted languages implement computationally expensive, > heavily used functions in the language instead of in a low-level C > library. In almost all cases where the code was not I/O bound, there > was a significant penalty for writing such functions. Rewriting > those functions in C/C++ often gave one or two orders of magnitude > improvement. Fine. But you have to know which ones. Which means you have to have a sufficiently complete sufficiently working system to run real benchmarks to find out. I've implemented enough computationally intensive heavily used functions in my time to have learned that writing them first in the highest level language available can be a huge time saver in getting them right. Up until a year ago I had a PhD student working on data mining who decided to do all her coding in Python. That was the right decision for her. The code ran fast *enough*, and there wasn't any point optimising an algorithm when the point of her research was to find out what the algorithm should be. I've just finished co-supervising a 4th-year project where the student implemented an information retrieval engine in Common Lisp so that he could use Genetic Programming to learn a stemming algorithm. Common Lisp was fast *enough*, and it took a long time to figure out what his algorithm (not the learned algorithm) should be. Any time spent writing that in C would have slowed the project down, possibly preventing its completion. (The year before another student, trying to do the same thing in Java, came to grief. Mind you, he was a worse student, but the difficulty of coding anything in Java, compared with Lisp, certainly didn't help him.) > I know that the overall algorithm can make a huge difference, and > that we should not waste our time with premature optimization, but > at the same time we should not waste CPU time with belated > pessimization. If we can predict based on experience that something > (a) is likely to be heavily used and (b) will be more efficient in a > lower-level language then we should implement it in said language. I don't believe your prediction. unjoin/2 is useful, true, but it's not *that* useful. Writing an algorithm in Erlang isn't pessimisation and it hardly counts as "belated". If you think that badly of Erlang, why use it? > All the little inefficiencies can add up into a steaming great > system-wide inefficiency. The death of a thousand cuts. > > Now, that having been said, I have not devoted time (yet) to > studying the relative efficiency of Erlang-implemented operations > compared to C code. It is an amazingly tricky thing to do. Erlang is very bad at some things, like floating-point intensive computations, that C is very good at. It is very good at other things, like pattern matching and concurrency, that C is very bad at. Inter-language comparisons that use both languages effectively are as scarce as hen's teeth. (That is, a few have been constructed by wizards in the lab, but none are known in the wild.) > > Here's the old war story ploy. > > I once ported a C++ application to an IBM mainframe - which had > (gasp!) a C++ compiler - and saw the mainframe get absolutely > *caned* by my laptop performance-wise in many cases. Investigation > at that time revealed that although the mainframe wiped out my > laptop in terms of I/O speed and bandwidth, my laptop just smoked > the IBM when it came to what goes on in the Web: dynamic string > processing and lots of memory allocations and deallocations. IBM, > seeing the writing on the wall, modified its hardware architecture, > IIRC by adding special string opcodes, and improved its runtime > libraries, to support more efficient string-processing and better > dynamic memory handling. The z/Series ISA is readily available on the Web. The /360 always *had* special string opcodes. Some of the new opcodes add Unicode support. Dynamic memory handling is a library issue, and there are good, so-so, and spectacularly bad C and C++ libraries for that job. In this case, it had nothing to do with the hardware, but with the system library. I suspect that it was (ab)using GETMAIN instead of running suballocators. I don't know why the "gasp!"; IBM mainframes had C compilers, quite good ones for the time, before C++ was commonly available on most UNIX systems. The really funny thing here is that C++ strings are notorious. I'm sure it would have been easy to beat C++ on the laptop. From mats.westin Fri Oct 10 07:21:33 2008 From: mats.westin (Mats Westin) Date: Fri, 10 Oct 2008 07:21:33 +0200 Subject: [erlang-questions] Are there any companies that hire Erlangers? In-Reply-To: <2a67d3ff0810091808x2c4be63dpbe1ef8f79654593c@mail.gmail.com> References: <2a67d3ff0810091808x2c4be63dpbe1ef8f79654593c@mail.gmail.com> Message-ID: 2008/10/10 G.S. : > Hello All, > > I have yet to find a company that programs using Erlang, and I'd really like > to work for one. Am I looking in the wrong place, do any of you know a > company that uses Erlang as the main language? > > -Gene +1 -- http://www.linkedin.com/in/matswestin From erlang-questions_efine Fri Oct 10 07:24:03 2008 From: erlang-questions_efine (Edwin Fine) Date: Fri, 10 Oct 2008 01:24:03 -0400 Subject: [erlang-questions] erlang-questions Digest, Vol 17, Issue 45 In-Reply-To: References: <8f24f4b10810091203i6eeb60f5q1b6bdaa483abea79@mail.gmail.com> <6c2563b20810091252l199969a3v2d82a5d9f87e0e91@mail.gmail.com> <8f24f4b10810091314r1586e999n999ffd972068e072@mail.gmail.com> <61EC12E1-6393-4427-846D-8B5DDC12B4D3@cs.otago.ac.nz> <6c2563b20810091911j581553d9s1f7bcc766620c48c@mail.gmail.com> Message-ID: <6c2563b20810092224s1329d172s7ef39932018cdb51@mail.gmail.com> On Thu, Oct 9, 2008 at 11:53 PM, Richard O'Keefe wrote: > On 10 Oct 2008, at 3:11 pm, Edwin Fine wrote: > >> Ok, then to preserve the Principle Of Least Astonishment, let string:split >> accept a regular expression, which is just a string with special RE >> operators. If the string contains no RE operators, use an optimized special >> case of split (like the one you wrote) that does not use an RE engine. Get >> the best of both worlds. >> > > No, that *violates* the principle of least astonishment, Big Time! > > First, absolutely nothing else whatever in the 'string' module > has anything to do with regular expressions. This would be > highly exceptional and very confusing. > I disagree. Take for example the String classes of Ruby ( http://www.ruby-doc.org/core/classes/String.html#M000818), JavaScript ( http://www.w3schools.com/jsref/jsref_split.asp) and Java ( http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#split(java.lang.String)), all of which use split with an RE. It's very intuitive to use and doesn't seem odd or out of place in a string class or module at all. One could argue that strings and regular expressions are inextricably intertwined (Python, on the other hand, uses split in its re class as far as I can see, so it's not universally true). > Second, something that splits strings using regular expressions > would be expected in the 'regexp' module, not the 'string' module. > In fact, regexp:split/2 already exists. It would be rather > astonishing to replicate this in the wrong module. > I think it's a matter of taste or opinion. I don't think split belongs in the regexp module. The new re module correctly does not include it. I think regexp:split should be deprecated, in fact, the entire regexp module should be deprecated because enough people have used it and been burned by its lack of performance (because it is written in Erlang when it should have been written in C) that it warrants an entire Caveat section in the Erlang Efficiency Guide. > Third, if there were a string:split/2 that used regular > expressions, that would make it very incompatible with > string:join/2, which doesn't. I thought we were wanting > string:join(string:split(String, Sep), Sep) > to give back Sep. > Did you mean to write "to give back String?" Yes, that is what we want, and it is what will happen, because it is meaningless to join using an RE, isn't it. You can't join things together with a regular expression. So Sep would *have* to be a literal string. As it happens, split and join work exactly like this in other languages and don't seem to overly confuse people. > In short, if you want something called 'split' that preserves > the principle of least astonishment, use regexp:split/2. > If you want an opposite of string:join/2, DON'T make it use > regular expressions, and DON'T call i split/2. > So we are stuck with contriving some name because of history (lists:split should have been lists:split_as from Haskell, regexp already has split). This, in spite of there being more than enough precedents amongst other languages that use split as a method of their String classes. By the way, I have a use for > string:join(reverse([Stuff|tail(reverse( > string:unjoin(Thing, ".")))]), ".") > so I would be very unhappy to have to write one of > those string literals as "\\." and the other NOT. > That's a VERY good point. It's a glaring inconsistency. Other languages deal with that by having a regular expression type and special syntax (e.g. /abc/ or %r{abc}) to avoid confusion, and (IIRC) if a string type is passed in stead of an RE type, the receiving method treats it as a non-RE. One would then be able to use the same literal in both join and unjoin. Maybe Erlang should have a new regular expression type and syntax, seeing as it is going to be used in more and more applications that do heavy text processing. > There is, or should be, a regular pattern > words <-> unwords > lines <-> unlines > unjoin <-> join > Oh well, sort of regular... > > Sorry, and no offense meant, but that's really horribly ugly. > So you really hate it that English has "tie" and "untie", > "do" and "undo", "wary" and "unwary", amongst many pairs? > Maybe it's because I'm accustomed to the words "tie" and "untie" and the others you mentioned, and unlines, unwords and so on just sound ghastly to me due to lack of familiarity. I honestly can't intuit what unwords and unlines do. Well, that's not true. If I think about it, I suppose lines would split a string into lines (similarly "words" would split a string into words), and unlines would "undo" the lines operation and join them back together. But I did have to think about it for a while. Maybe I'm not that smart. > > Reminds me of that sentence, "A not unblack dog chased a not unbrown >> rabbit across a not ungreen field." >> > > Straw man. The nasty thing about that sentence is the double > negations. There is no double negation in unjoin. Yes, that is true, but in my eyes it's not only the double negation that's ugly. I was citing that sentence to show the ugliness of using "un" in places that are unusual. Note: "un" is not unusual in "unusual." > "unwords" and "unlines" are not my inventions, they are > from the Haskell standard Prelude. There is no intended irony or sarcasm in this: seeing as the inventors of Haskell are undoubtedly smarter than I am, I defer to their superior intelligence, but those words are still ugly to me. Sorry. > > Should the opposite of down then be "undown"? Languages (well, I can vouch >> for two, anyway) contain many complementary words that are not syntactically >> constructable by adding or removing "un-". >> > > What of it? The words/unwords lines/unline pattern DOES exist > in the language Erlang copied many of its list processing > function names from. It's not my invention. Indeed, the > Haskell community is as familiar with "unfold" as with "fold". > In this specific context, UNdoing the effect of a list > operation, "un-" is an excellent cultural fit. Fold and unfold are words in the English dictionary, and I can't swear to it because I am too lazy to look it up, but I would suspect that "unwords" and "unlines" are not. Still, I take your point. One can get used to almost anything given time. Not being a Haskell initiate, the usage looks strange to me. > The fact that for example "add" and "subtract" are not related > in that way really doesn't signify anything, just as the fact > that there are many colours doesn't mean that black is a bad > choice. But you wouldn't create a function named "unadd" when "subtract " is a more acceptable usage - would you? > Like split and join, for example. Hard and soft. Big and small. Break and >> mend. Wake and sleep. >> > > Join is also related to sever, disunite, unfasten, disconnect, unyoke, > separate, put asunder, unlink, disassociate, disaffiliate, resign, > detach, disengage, leave, part, divide, quit, ... > Interesting. One of the words you wrote above gave me an idea. How about meeting halfway? How about two new functions, string:separate(String, Separator) and string:unseparate(List, Separator)? No clash and it makes even more sense (to me) than split and join. Split is also related to unite, unify, connect, fragm?nt (stress shown), > and another whole lot of words. > > It's not as if "split" and "join" were each other's _only_ relative. > Point(s) well taken. How do you feel about "separate" and "unseparate", then? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081010/8a35d300/attachment.html From bengt.kleberg Fri Oct 10 08:03:58 2008 From: bengt.kleberg (Bengt Kleberg) Date: Fri, 10 Oct 2008 08:03:58 +0200 Subject: [erlang-questions] Adding simple process to supervisor? In-Reply-To: <28655359.11621223585023526.JavaMail.root@zimbra> References: <28655359.11621223585023526.JavaMail.root@zimbra> Message-ID: <1223618638.3831.78.camel@seasc0642.dyn.rnd.as.sw.ericsson.se> Greetings, After suggestions from the list I have have tried the "proc_lib creates special process" method. It meant using proc_lib:start_link/3, calling proc_lib:init_ack/2, adding receive of system messages (2 lines) and 2 exported call-back functions (1 line each). That was acceptable complications too me since I keep all the restarting in the supervisor. Note that I think using your method would have been fewer lines. However, the process blocks in gen_tcp:accept/1, thus missing any system messages during this time. Is there a way around that? bengt On Thu, 2008-10-09 at 21:43 +0100, Oscar Hellstr?m wrote: > Hi Bengt, > > What I usually do is just to spawn a reader process from the gen_server and link to it. Then depending on if the gen_server should die with errors in the reader process or not I sometimes traps exits in the gen_server. Most of the time you want to restart the gen_server to open a new socket if the reader dies anyway. IMHO, there are too many issues with trying to get a process that does blocking calls to exist under a supervisor and this kind of process is typically very simple (read small room for errors) as well. Another approach is to use proc_lib to create a "special process" which uses {active, once} for the socket, to get away from doing blocking calls. > > ----- Original Message ----- > From: "Bengt Kleberg" > To: "erlang-questions" > Sent: Thursday, 9 October, 2008 12:03:27 AM GMT -08:00 US/Canada Pacific > Subject: [erlang-questions] Adding simple process to supervisor? > > Greetings, > > I have a gen_server which is supervised according to OTP rules. Now I > want to add a simple process that will read from a TCP port and send > the incoming data to the gen_server. I could spawn_link this process > from the gen_server and restart it if it dies. However, since I have a > supervisor it seems more logical to just add the process there, as a > rest_for_one. > > > There is the alternative of using a supervisor_bridge, but that seems > more complex than using the gen_server. It seems as if I just design > my process according to the OTP rules I will not need to use a > supervisor_bridge. What are those rules? The only suggestions I have > found are: > 1 Module:start_link/1 => {ok, Pid} > 2 Module:terminate/2 => ok > > > The child specification returned by the init/1 call-back in a > supervisor mentions the value for Modules if we have a gen_server, > gen_fsm or gen_event. What could be used for a simple process? > > > But how do I add a simple process to the supervisor? It seems overkill > to masquerade it as a get_fsm or similar. Since it is not called from > erlang it is not a gen_server. Since it does not have state it is not a > gen_fsm. No events are handled. > > > bengt > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From raimo+erlang-questions Fri Oct 10 08:35:17 2008 From: raimo+erlang-questions (Raimo Niskanen) Date: Fri, 10 Oct 2008 08:35:17 +0200 Subject: [erlang-questions] External file sorting In-Reply-To: References: Message-ID: <20081010063517.GA16638@erix.ericsson.se> On Thu, Oct 09, 2008 at 12:59:51PM +0200, ERLANG wrote: > Hi List, > > Is there some free Erlang code for external (i.e on disk) file sorting? > This module in stdlib might be what you are looking for: http://www.erlang.org/doc/man/file_sorter.html > cheers > Y. > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions -- / Raimo Niskanen, Erlang/OTP, Ericsson AB From kenneth.lundin Fri Oct 10 08:40:13 2008 From: kenneth.lundin (Kenneth Lundin) Date: Fri, 10 Oct 2008 08:40:13 +0200 Subject: [erlang-questions] Interesting: "Squeak VM adapted to run on Tilera" In-Reply-To: References: Message-ID: For your info we can also say that we have the Erlang SMP VM running on a 64 core Tilera. How many cores from 1 to 64 we use is configurable. It is actually not a very big deal to port the Erlang VM to Tilera since it is run on top of Linux there as well. Getting good performance and scalability is another thing. The Tilera is a good test bench for testing scalability over many cores and we expect to get much better scalability when we have finished the implementation of multiple run-queues. /Kenneth Erlang/OTP team, Ericsson On Fri, Oct 10, 2008 at 1:03 AM, G Bulmer wrote: > > Folks, I thought some might be interested in this ... > > Sam S. Adams and David Ungar (Self) have adapted the Squeak VM to run > on 56 of the 64 cores on the Tilera64 processor family. > "Exploring Massively Multicore Programming Models: Introducing the > Renaissance ER Project" > http://domino.watson.ibm.com/comm/research.nsf/pages/r.plansoft.seminars.html > > Mentioned by Sam Adams here: > http://wiki.squeak.org/squeak/1107 > > G Bulmer > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From b88zhou Fri Oct 10 08:47:04 2008 From: b88zhou (Brian Zhou) Date: Thu, 9 Oct 2008 23:47:04 -0700 Subject: [erlang-questions] write the ant simulation in Erlang? In-Reply-To: <3dbc6d1c0810091447ye7fbc56j9d7ee5f322dd1854@mail.gmail.com> References: <859e91e70810081456w244b1c9dh74e108325ae4135c@mail.gmail.com> <7D2420AE-BA6D-4EE4-85DD-CCB6C1723DBE@cs.otago.ac.nz> <859e91e70810082144v52c0998bi140a6116c67cf12a@mail.gmail.com> <859e91e70810082146k3457bd2evc813a51beda59989@mail.gmail.com> <3dbc6d1c0810091447ye7fbc56j9d7ee5f322dd1854@mail.gmail.com> Message-ID: <859e91e70810092347x5903f7fdva3f44f6db99f916c@mail.gmail.com> On Thu, Oct 9, 2008 at 2:47 PM, Robert Virding wrote: > I haven't really checked the Clojure code that closely but it seems like a > reasonable problem. > > Do you know if it "turn based" or do the all the ants just move after their > own clocks in a parallel way? The clojure implementation uses one thread for each ant. Each ant has their own clock. > > A first approximation would be to have one process per ant and one for the > world. The only problem would be handling atomic > look-at-the-immediate-world-around-me-and-make-a-move. > Strictly speaking, the world state should be version'ed, the world process should reject the move if the world has changed since the ant looked, the ant process then should retry look-decide-and-request-move. As an optimization, I guess the world process can just check whether the FPA (food, pheromone, ant) value of the target cell has changed. I wrote a rough first cut based on the above idea: http://pastebin.ca/1224362 - It's not completed yet, TODO: 1. pheromone evaporation 2. initialization of the world, spawn world process, spawn ant processes 3. scoring candidate cells Am I on the right track? > The really difficult bit is displaying it. :-) > I'm not there yet. Thanks, -Brian From vladdu55 Fri Oct 10 08:57:17 2008 From: vladdu55 (Vlad Dumitrescu) Date: Fri, 10 Oct 2008 08:57:17 +0200 Subject: [erlang-questions] Fwd: [enhancement] string:split/2 In-Reply-To: <95be1d3b0810092356lc2f1d93m5e86a0ecc97358cd@mail.gmail.com> References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> <6c2563b20810082343j255330ccp396cf4f8da0d2fe4@mail.gmail.com> <330AAA17-394B-44D0-9E09-7CEE4B6BF9C9@cs.otago.ac.nz> <6c2563b20810091932x245481ew538675b5526e8db3@mail.gmail.com> <8689C36E-B021-4300-88E1-AB66164891F6@cs.otago.ac.nz> <95be1d3b0810092356lc2f1d93m5e86a0ecc97358cd@mail.gmail.com> Message-ID: <95be1d3b0810092357l560fc443s717064b14cfb5677@mail.gmail.com> Hi, On Fri, Oct 10, 2008 at 07:00, Richard O'Keefe wrote: > On 10 Oct 2008, at 3:32 pm, Edwin Fine wrote: >> I'd rather ensure that the function is implemented efficiently to >> start off with, and not require HiPE to be used to get performance. > > Talking about "not requir[ing] HiPE" is like saying > "I demand that your C compiler produce efficient code > without optimisation." A side issue: the above comparison is not really correct. Until HiPE is available on all platforms and architectures supported by Erlang, it is perfectly valid to not want to have it as a requirement for an application. best regards, Vlad From btolputt Fri Oct 10 07:25:29 2008 From: btolputt (Benjamin Tolputt) Date: Fri, 10 Oct 2008 16:25:29 +1100 Subject: [erlang-questions] [enhancement] string:split/2 In-Reply-To: <8689C36E-B021-4300-88E1-AB66164891F6@cs.otago.ac.nz> References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> <6c2563b20810082343j255330ccp396cf4f8da0d2fe4@mail.gmail.com> <330AAA17-394B-44D0-9E09-7CEE4B6BF9C9@cs.otago.ac.nz> <6c2563b20810091932x245481ew538675b5526e8db3@mail.gmail.com> <8689C36E-B021-4300-88E1-AB66164891F6@cs.otago.ac.nz> Message-ID: <48EEE749.7000100@bigpond.net.au> Richard O'Keefe wrote: > Talking about "not requir[ing] HiPE" is like saying > "I demand that your C compiler produce efficient code > without optimisation." Setting compiler options routinely > produces more than a factor of 2 in C speed these days. > (Even with the Intel C compiler, I found changing from > its default options gave me a factor of 2.) While I agree with nigh on all the rest of your post, I take issue with the above statement for one simple reason... HiPE does not run on Windows. Depending on the system being put together this ranges between non-applicable to "deal breaker". In cases involving string processing - Windows is a very likely candidate for the platform on which the application will be run. As someone who sees Erlang as being applicable beyond the clustered server paradigm, performance on the operating system used in 90+% desktop installations is incredibly important. -- Regards, Benjamin Tolputt Analyst Programmer Email: btolputt This email and any files transmitted with it are confidential to the intended recipient and may be privileged. If you have received this email inadvertently or you are not the intended recipient, you may not disseminate, distribute, copy or in any way rely on it. Further, you should notify the sender immediately and delete the email from your computer. Whilst we have taken precautions to alert us to the presence of computer viruses, we cannot guarantee that this email and any files transmitted with it are free from such viruses. From ulf.wiger Fri Oct 10 09:47:06 2008 From: ulf.wiger (Ulf Wiger (TN/EAB)) Date: Fri, 10 Oct 2008 09:47:06 +0200 Subject: [erlang-questions] Adding simple process to supervisor? In-Reply-To: <1223618638.3831.78.camel@seasc0642.dyn.rnd.as.sw.ericsson.se> References: <28655359.11621223585023526.JavaMail.root@zimbra> <1223618638.3831.78.camel@seasc0642.dyn.rnd.as.sw.ericsson.se> Message-ID: <48EF087A.6060600@ericsson.com> Bengt Kleberg skrev: > > However, the process blocks in gen_tcp:accept/1, thus missing any > system messages during this time. Is there a way around that? You can spawn an acceptor process and then transfer control using controlling_process(). The acceptor process has but one job: to block while waiting for the accept() to return. It is linked to the parent process and doesn't trap exits. BR, Ulf W From bgustavsson Fri Oct 10 10:26:08 2008 From: bgustavsson (Bjorn Gustavsson) Date: Fri, 10 Oct 2008 10:26:08 +0200 Subject: [erlang-questions] Bug in string:to_{lower,upper}/1? In-Reply-To: <5EBB3A16-726D-41C7-B295-280E83161232@cs.otago.ac.nz> References: <5EBB3A16-726D-41C7-B295-280E83161232@cs.otago.ac.nz> Message-ID: <6672d0160810100126j1b6555d1u532b1c113bdb2380@mail.gmail.com> On Fri, Oct 10, 2008 at 6:16 AM, Richard O'Keefe wrote: > In string.erl we find > > to_lower_char(C) when is_integer(C), C >= $A, C =< $Z -> > C + 32; > to_lower_char(C) when is_integer(C), C >= 16#C1, C =< 16#D6 -> > C + 32; > to_lower_char(C) when is_integer(C), C >= 16#D8, C =< 16#DE -> > C + 32; > to_lower_char(C) -> > C. > > to_upper_char(C) when is_integer(C), C >= $a, C =< $z -> > C - 32; > to_upper_char(C) when is_integer(C), C >= 16#E1, C =< 16#F6 -> > C - 32; > to_upper_char(C) when is_integer(C), C >= 16#F8, C =< 16#FE -> > C - 32; > to_upper_char(C) -> > C. > > But 16#C0 is capital A with grave, > which is an upper case letter that should be converted, > and to_lower_char/1 does not recognise it. > I think 16#C1 should be 16#C0. > > And 16#E0 is lower case A with grave, > which is a lower case letter that should be converted, > but to_upper_char/1 does not recognise it. > I think 16#E1 should be 16#E0. > Thanks for pointing this out. We will correct this problem in R12B-5. /Bjorn -- Bj?rn Gustavsson, Erlang/OTP, Ericsson AB -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081010/144e59f8/attachment.html From tty.erlang Fri Oct 10 13:10:45 2008 From: tty.erlang (t ty) Date: Fri, 10 Oct 2008 07:10:45 -0400 Subject: [erlang-questions] Are there any companies that hire Erlangers? In-Reply-To: <6c2563b20810091937u2b411cean65d972caa4d60bd9@mail.gmail.com> References: <2a67d3ff0810091808x2c4be63dpbe1ef8f79654593c@mail.gmail.com> <6c2563b20810091937u2b411cean65d972caa4d60bd9@mail.gmail.com> Message-ID: <290b3ba10810100410k205642demb8ec48b7f361a3e4@mail.gmail.com> Erlang Training and Consulting has a jobs page which you might want to subscribe to http://www.erlang-consulting.com/jobs.html For the record I don't work for ETC :) t 2008/10/9 Edwin Fine : > Not to be funny, but in which country? I mean, where are you looking? In the > U.K for example, I think I know of a company or two that uses primarily > Erlang (Erlang Training and Consulting is one, and I think LShift is another > - http://www.lshift.net/recruitment). > > 2008/10/9 G.S. >> >> Hello All, >> >> I have yet to find a company that programs using Erlang, and I'd really >> like to work for one. Am I looking in the wrong place, do any of you know a >> company that uses Erlang as the main language? >> >> -Gene >> >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions >> http://www.erlang.org/mailman/listinfo/erlang-questions > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From tty.erlang Fri Oct 10 13:23:01 2008 From: tty.erlang (t ty) Date: Fri, 10 Oct 2008 07:23:01 -0400 Subject: [erlang-questions] 2008 Workshop Presentation Slides Available Message-ID: <290b3ba10810100423v4eba5713va4e55ee248ce7c8b@mail.gmail.com> ===================================================================== Workshop Presentation Slides Available The 7th ACM SIGPLAN Erlang Workshop 2008 http://www.erlang.org/workshop/2008/ Victoria, BC, Canada, 27 September 2008 ===================================================================== The presentation slides for the 7th ACM SIGPLAN Erlang Workshop in Victoria, British Columbia, Canada, held on September 27 are now available at http://www.erlang.org/workshop/2008/ Workshop papers can be obtained from the ACM Digital Library. Please feel free to distribute this announcement to any other interested mailing-list. From kostis Fri Oct 10 13:33:12 2008 From: kostis (Kostis Sagonas) Date: Fri, 10 Oct 2008 14:33:12 +0300 Subject: [erlang-questions] Types and specs [WAS: [enhancement] string:split/2] In-Reply-To: References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> Message-ID: <48EF3D78.2060306@cs.ntua.gr> Richard O'Keefe wrote: > > Can anyone explain to me why > > -spec(tokens/2 :: (string(), string()) -> [[char(),...]]). > > doesn't mention "string()" on the right hand side of the arrow? There is no native string() type in Erlang, as we all well know. So, in the language ot types, string() is just an alias for the type list(char()), which, for convenience, is typically written as [char()]. This can include both the empty string "" == [] and a non-empty list of characters, which is denoted [char(),...]. That's what the above spec signifies: the resulting list consists of non-empty strings, which is consistent with what string:tokens/2 actually returns. Hope this explains things. On the other hand, I can see how this may look a bit strange to some and have for a long time now pondered whether a non_empty_string() type alias might be added to the list of built-in types. Kostis From ash Fri Oct 10 14:04:01 2008 From: ash (Alex Chateau) Date: Fri, 10 Oct 2008 15:04:01 +0300 Subject: [erlang-questions] [enhancement] string:split/2 In-Reply-To: <6c2563b20810090953n1b0c7672v17ceb84cbb59a1fd@mail.gmail.com> References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> <34A27838-5CBA-425D-97A1-C2D2CF6F5456@cs.otago.ac.nz> <6c2563b20810082354u34372510n1fb4e1d23d777c23@mail.gmail.com> <781bce43-97e9-48fb-bba2-0ce230f2011a@t39g2000prh.googlegroups.com> <6c2563b20810090953n1b0c7672v17ceb84cbb59a1fd@mail.gmail.com> Message-ID: <20081010120401.GA3909@tsi.lv> On Thu, Oct 09, 2008 at 12:53:52PM -0400, Edwin Fine wrote: > > > > > > Do you mean that string:split should be the _inverse_ of string:join? > > > > http://en.wikipedia.org/wiki/Inverse_function > > > Yes, that's it. Thanks. I just wish there was a more impressive-sounding > word like idempotent :) string:join/2 is not a surjective function, not a bijective one: 1> string:join(["a.", "b"], "."). "a..b" 2> string:join(["a", ".b"], "."). "a..b" So, there is no inverse function for string:join/2 http://en.wikipedia.org/wiki/Bijection http://en.wikipedia.org/wiki/Surjection -- Alex Chateau From saleyn Fri Oct 10 14:19:51 2008 From: saleyn (Serge Aleynikov) Date: Fri, 10 Oct 2008 08:19:51 -0400 Subject: [erlang-questions] Adding simple process to supervisor? In-Reply-To: <1223618638.3831.78.camel@seasc0642.dyn.rnd.as.sw.ericsson.se> References: <28655359.11621223585023526.JavaMail.root@zimbra> <1223618638.3831.78.camel@seasc0642.dyn.rnd.as.sw.ericsson.se> Message-ID: <48EF4867.6080703@gmail.com> If you need a completely non-blocking solution, you can read this article: http://www.trapexit.org/Building_a_Non-blocking_TCP_server_using_OTP_principles Serge Bengt Kleberg wrote: > Greetings, > > After suggestions from the list I have have tried the "proc_lib creates > special process" method. It meant using proc_lib:start_link/3, calling > proc_lib:init_ack/2, adding receive of system messages (2 lines) and 2 > exported call-back functions (1 line each). That was acceptable > complications too me since I keep all the restarting in the supervisor. > Note that I think using your method would have been fewer lines. > > However, the process blocks in gen_tcp:accept/1, thus missing any system > messages during this time. Is there a way around that? > > > bengt > > On Thu, 2008-10-09 at 21:43 +0100, Oscar Hellstr?m wrote: >> Hi Bengt, >> >> What I usually do is just to spawn a reader process from the gen_server and link to it. Then depending on if the gen_server should die with errors in the reader process or not I sometimes traps exits in the gen_server. Most of the time you want to restart the gen_server to open a new socket if the reader dies anyway. IMHO, there are too many issues with trying to get a process that does blocking calls to exist under a supervisor and this kind of process is typically very simple (read small room for errors) as well. Another approach is to use proc_lib to create a "special process" which uses {active, once} for the socket, to get away from doing blocking calls. >> >> ----- Original Message ----- >> From: "Bengt Kleberg" >> To: "erlang-questions" >> Sent: Thursday, 9 October, 2008 12:03:27 AM GMT -08:00 US/Canada Pacific >> Subject: [erlang-questions] Adding simple process to supervisor? >> >> Greetings, >> >> I have a gen_server which is supervised according to OTP rules. Now I >> want to add a simple process that will read from a TCP port and send >> the incoming data to the gen_server. I could spawn_link this process >> from the gen_server and restart it if it dies. However, since I have a >> supervisor it seems more logical to just add the process there, as a >> rest_for_one. >> >> >> There is the alternative of using a supervisor_bridge, but that seems >> more complex than using the gen_server. It seems as if I just design >> my process according to the OTP rules I will not need to use a >> supervisor_bridge. What are those rules? The only suggestions I have >> found are: >> 1 Module:start_link/1 => {ok, Pid} >> 2 Module:terminate/2 => ok >> >> >> The child specification returned by the init/1 call-back in a >> supervisor mentions the value for Modules if we have a gen_server, >> gen_fsm or gen_event. What could be used for a simple process? >> >> >> But how do I add a simple process to the supervisor? It seems overkill >> to masquerade it as a get_fsm or similar. Since it is not called from >> erlang it is not a gen_server. Since it does not have state it is not a >> gen_fsm. No events are handled. >> >> >> bengt >> >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions >> http://www.erlang.org/mailman/listinfo/erlang-questions >> > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From r.b.lists Fri Oct 10 15:00:23 2008 From: r.b.lists (Roland Braito) Date: Fri, 10 Oct 2008 15:00:23 +0200 Subject: [erlang-questions] Are there any companies that hire Erlangers? In-Reply-To: <290b3ba10810100410k205642demb8ec48b7f361a3e4@mail.gmail.com> References: <2a67d3ff0810091808x2c4be63dpbe1ef8f79654593c@mail.gmail.com> <6c2563b20810091937u2b411cean65d972caa4d60bd9@mail.gmail.com> <290b3ba10810100410k205642demb8ec48b7f361a3e4@mail.gmail.com> Message-ID: <20081010130023.30940@gmx.net> I have got some offers since i have put up my interest in erlang in my profile on Xing.com -------- Original-Nachricht -------- > Datum: Fri, 10 Oct 2008 07:10:45 -0400 > Von: "t ty" > An: "Edwin Fine" > CC: erlang-questions > Betreff: Re: [erlang-questions] Are there any companies that hire Erlangers? > Erlang Training and Consulting has a jobs page which you might want to > subscribe to > > http://www.erlang-consulting.com/jobs.html > > For the record I don't work for ETC :) > > t > > 2008/10/9 Edwin Fine : > > Not to be funny, but in which country? I mean, where are you looking? In > the > > U.K for example, I think I know of a company or two that uses primarily > > Erlang (Erlang Training and Consulting is one, and I think LShift is > another > > - http://www.lshift.net/recruitment). > > > > 2008/10/9 G.S. > >> > >> Hello All, > >> > >> I have yet to find a company that programs using Erlang, and I'd really > >> like to work for one. Am I looking in the wrong place, do any of you > know a > >> company that uses Erlang as the main language? > >> > >> -Gene > >> > >> _______________________________________________ > >> erlang-questions mailing list > >> erlang-questions > >> http://www.erlang.org/mailman/listinfo/erlang-questions > > > > > > _______________________________________________ > > erlang-questions mailing list > > erlang-questions > > http://www.erlang.org/mailman/listinfo/erlang-questions > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions -- GMX Kostenlose Spiele: Einfach online spielen und Spa? haben mit Pastry Passion! http://games.entertainment.gmx.net/de/entertainment/games/free/puzzle/6169196 From armstrong.whit Fri Oct 10 15:21:37 2008 From: armstrong.whit (Whit Armstrong) Date: Fri, 10 Oct 2008 09:21:37 -0400 Subject: [erlang-questions] Article on Erlang in ACM Queue In-Reply-To: <48ED943A.80801@berabera.info> References: <48ED943A.80801@berabera.info> Message-ID: <8ec76080810100621r48b0a482j1e02ad8bf5788a58@mail.gmail.com> I'm new to Erlang. I've been considering it for a few simulation projects in finance. However, I was discouraged because the ACM article suggests that Erlang has poor floating point performance. Are any list members using Erlang for numerical simulations? If so, do you have any advice on how to how to improve efficiency? What about using binaries to store vectors of doubles? Are there any extensions of Erlang that allow one to do that? Any feedback is appreciated. Thanks, Whit On Thu, Oct 9, 2008 at 1:18 AM, Romain Lenglet wrote: > Jim Larson has written an article entitled "Erlang for Concurrent > Programming", published in the latest ACM Queue: > http://mags.acm.org/queue/200809/ > > This article is a very good, practical introduction to Erlang and OTP. > > -- > Romain Lenglet > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From saleyn Fri Oct 10 15:42:19 2008 From: saleyn (Serge Aleynikov) Date: Fri, 10 Oct 2008 09:42:19 -0400 Subject: [erlang-questions] jinterface bug Message-ID: <48EF5BBB.5080207@gmail.com> While working with otp.net I encountered a fairly serious bug that has its origin in jinterface. The later doesn't detect remote node disconnects. Attached patch addresses the issue. Serge -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: AbstractConnection.java.patch Url: http://www.erlang.org/pipermail/erlang-questions/attachments/20081010/6d631ead/attachment.ksh From Bill.McKeeman Fri Oct 10 15:46:43 2008 From: Bill.McKeeman (Bill McKeeman) Date: Fri, 10 Oct 2008 09:46:43 -0400 Subject: [erlang-questions] Article on Erlang in ACM Queue In-Reply-To: <8ec76080810100621r48b0a482j1e02ad8bf5788a58@mail.gmail.com> References: <48ED943A.80801@berabera.info> <8ec76080810100621r48b0a482j1e02ad8bf5788a58@mail.gmail.com> Message-ID: I think it depends on how much you can do in parallel and how much is really floating point as contrasted to function calls and the like. I wrote a numerical integration routine with a parameter N for the number of cores I expected to use. Even with N = 2 it was better than some competing sequential versions. I'll attach the code. /s/Bill -----Original Message----- From: erlang-questions-bounces [mailto:erlang-questions-bounces] On Behalf Of Whit Armstrong Sent: Friday, October 10, 2008 9:22 AM To: Erlang mailing list Subject: Re: [erlang-questions] Article on Erlang in ACM Queue I'm new to Erlang. I've been considering it for a few simulation projects in finance. However, I was discouraged because the ACM article suggests that Erlang has poor floating point performance. Are any list members using Erlang for numerical simulations? If so, do you have any advice on how to how to improve efficiency? What about using binaries to store vectors of doubles? Are there any extensions of Erlang that allow one to do that? Any feedback is appreciated. Thanks, Whit On Thu, Oct 9, 2008 at 1:18 AM, Romain Lenglet wrote: > Jim Larson has written an article entitled "Erlang for Concurrent > Programming", published in the latest ACM Queue: > http://mags.acm.org/queue/200809/ > > This article is a very good, practical introduction to Erlang and OTP. > > -- > Romain Lenglet > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > _______________________________________________ erlang-questions mailing list erlang-questions http://www.erlang.org/mailman/listinfo/erlang-questions -------------- next part -------------- A non-text attachment was scrubbed... Name: pquadn.erl Type: application/octet-stream Size: 1711 bytes Desc: pquadn.erl Url : http://www.erlang.org/pipermail/erlang-questions/attachments/20081010/5ed10edd/attachment-0001.obj From nicolas Fri Oct 10 16:01:22 2008 From: nicolas (Nicolas Niclausse) Date: Fri, 10 Oct 2008 16:01:22 +0200 Subject: [erlang-questions] Article on Erlang in ACM Queue In-Reply-To: <8ec76080810100621r48b0a482j1e02ad8bf5788a58@mail.gmail.com> References: <48ED943A.80801@berabera.info> <8ec76080810100621r48b0a482j1e02ad8bf5788a58@mail.gmail.com> Message-ID: <48EF6032.8080400@niclux.org> Whit Armstrong ecrivait le 10.10.2008 15:21: > I'm new to Erlang. I've been considering it for a few simulation > projects in finance. However, I was discouraged because the ACM > article suggests that Erlang has poor floating point performance. > > Are any list members using Erlang for numerical simulations? If so, > do you have any advice on how to how to improve efficiency? What > about using binaries to store vectors of doubles? Are there any > extensions of Erlang that allow one to do that? Take a look at the slides "High-performance Technical Computing with Erlang " recently published in http://www.erlang.org/workshop/2008/ It seems very promising. I'm waiting for a code release ! -- Nicolas From ulf.wiger Fri Oct 10 16:03:18 2008 From: ulf.wiger (Ulf Wiger (TN/EAB)) Date: Fri, 10 Oct 2008 16:03:18 +0200 Subject: [erlang-questions] Article on Erlang in ACM Queue In-Reply-To: <8ec76080810100621r48b0a482j1e02ad8bf5788a58@mail.gmail.com> References: <48ED943A.80801@berabera.info> <8ec76080810100621r48b0a482j1e02ad8bf5788a58@mail.gmail.com> Message-ID: <48EF60A6.10400@ericsson.com> Whit Armstrong skrev: > I'm new to Erlang. I've been considering it for a few simulation > projects in finance. However, I was discouraged because the ACM > article suggests that Erlang has poor floating point performance. > > Are any list members using Erlang for numerical simulations? If so, > do you have any advice on how to how to improve efficiency? What > about using binaries to store vectors of doubles? Are there any > extensions of Erlang that allow one to do that? Perhaps this might at least give you some initial intuition: High-performance Technical Computing with Erlang Alceste Scalas Giovanni Casu Piero Pili Center for Advanced Studies, Research and Development in Sardinia ACM ICFP 2008 / Erlang Workshop September 27th, 2008 Victoria, BC, Canada http://www.erlang.org/workshop/2008/Sess23.pdf BR, Ulf W From saleyn Fri Oct 10 16:04:01 2008 From: saleyn (Serge Aleynikov) Date: Fri, 10 Oct 2008 10:04:01 -0400 Subject: [erlang-questions] code_server & ERL_LIBS bug Message-ID: <48EF60D1.1030704@gmail.com> There's an error in code server that causes erl & erlc to hang at startup if ERL_LIBS environment variable is set to an empty string or a string containing non-existing directories. Here's how to reproduce it: $ export ERL_LIBS= $ erl or $ export ERL_LIBS="/a/b/c" $ erl Attached patch corrects the problem. Regards, Serge -------------- next part -------------- A non-text attachment was scrubbed... Name: code_server.erl.patch Type: application/octet-stream Size: 1157 bytes Desc: not available Url : http://www.erlang.org/pipermail/erlang-questions/attachments/20081010/5881ecd2/attachment.obj From juanjo Fri Oct 10 16:07:52 2008 From: juanjo (Juan Jose Comellas) Date: Fri, 10 Oct 2008 11:07:52 -0300 Subject: [erlang-questions] Are there any companies that hire Erlangers? In-Reply-To: <2a67d3ff0810091808x2c4be63dpbe1ef8f79654593c@mail.gmail.com> References: <2a67d3ff0810091808x2c4be63dpbe1ef8f79654593c@mail.gmail.com> Message-ID: <1c3be50f0810100707x1dafca95pf173a22fc20c752e@mail.gmail.com> We use Erlang for some of our projects and we are always looking for people with good skills and knowledge of the language. So far we've never found anybody who already knew Erlang in Argentina so we've been training our employees ourselves. We have offices in Buenos Aires and San Luis, a bit far from the countries where most Erlang developers reside, but we already have 12 people working in Erlang at our company (http://www.novamens.com). 2008/10/9 G.S. > Hello All, > > I have yet to find a company that programs using Erlang, and I'd really > like to work for one. Am I looking in the wrong place, do any of you know a > company that uses Erlang as the main language? > > -Gene > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081010/448b3f78/attachment.html From ash Fri Oct 10 16:09:50 2008 From: ash (Alex Chateau) Date: Fri, 10 Oct 2008 17:09:50 +0300 Subject: [erlang-questions] [enhancement] string:split/2 In-Reply-To: <20081010120401.GA3909@tsi.lv> References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> <34A27838-5CBA-425D-97A1-C2D2CF6F5456@cs.otago.ac.nz> <6c2563b20810082354u34372510n1fb4e1d23d777c23@mail.gmail.com> <781bce43-97e9-48fb-bba2-0ce230f2011a@t39g2000prh.googlegroups.com> <6c2563b20810090953n1b0c7672v17ceb84cbb59a1fd@mail.gmail.com> <20081010120401.GA3909@tsi.lv> Message-ID: <20081010140950.GB3909@tsi.lv> > string:join/2 is not a surjective function, not a bijective one: Sorry, string:join/2 _is_ a surjective function -- Alex Chateau From erik.stenman Fri Oct 10 16:22:46 2008 From: erik.stenman (Erik Stenman) Date: Fri, 10 Oct 2008 16:22:46 +0200 Subject: [erlang-questions] Are there any companies that hire Erlangers? In-Reply-To: <2a67d3ff0810091808x2c4be63dpbe1ef8f79654593c@mail.gmail.com> References: <2a67d3ff0810091808x2c4be63dpbe1ef8f79654593c@mail.gmail.com> Message-ID: Kreditor is using Erlang for almost all of our development. We are currently hiring two to three erlang developers, a head of development, a technical project manager, one operations engineer and one support engineer. If you want to know more about any of these positions, just drop me a line. On 10 okt 2008, at 03.08, G.S. wrote: > Hello All, > > I have yet to find a company that programs using Erlang, and I'd > really like to work for one. Am I looking in the wrong place, do any > of you know a company that uses Erlang as the main language? > > -Gene > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions Erik Stenman ? CTO KREDITOR EUROPE AB Sankt Eriksgatan 117 113 43, Stockholm Vxl: +46 8 120 120 00 Fax: +46 8 120 120 99 Webb: www.kreditor.se E-mail: erik.stenman -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081010/d7a86a0b/attachment.html From n39052 Fri Oct 10 17:09:14 2008 From: n39052 (Sergey A.) Date: Fri, 10 Oct 2008 08:09:14 -0700 Subject: [erlang-questions] Lots of questions about error_logger Message-ID: <3bff71aa0810100809w1b5282dfhd7bd06876f255605@mail.gmail.com> Hello. In the first place, sorry for several different questions placed in one letter. I know it's something wearily to answer a list of questions. I tried using error_logger as a tool for handling error reports and I've came across some oddities: #1. Is there a way to set SASL options (I'm about sasl_error_logger, errlog_type etc) from the Erlang code at runtime without using a .config file + the "-config" argument? I just want to give an end user only one config file to edit and use values from that to setup SASL. #2. The following is from the "Programming Erlang": --[Beginning of quote]------------------------------------------------- The next configuration file lists error reports in the shell, and a copy of everything reported in the shell is also made to a file: %% single text file - minimal tty [{sasl, [ %% All reports go to this file {sasl_error_logger, {file, "/home/joe/error_logs/THELOG" }} ]}]." --[End of quote]------------------------------------------------- I replaced the path to just "THELOG" and then run the shell: --[Beginning of erl session]------------------------------------------------- erl -boot start_sasl -config elog2.config Erlang (BEAM) emulator version 5.6.3 [source] [smp:2] [async-threads:0] [hipe] [kernel-poll:false] Eshell V5.6.3 (abort with ^G) 1> error_logger:error_msg("foobar~n"). ok =ERROR REPORT==== 10-Oct-2008::03:19:38 === foobar 2> error_logger:error_report("foobar\n"). =ERROR REPORT==== 10-Oct-2008::03:21:05 === foobar ok 3> User switch command --> q --[End of erl session]------------------------------------------------- But after all, THELOG doesn't contain any string related to my foobar-errors! Just only progress reports! Why does this happen? #3. If I decide to use rotating of logs, those logs will be written in binary format. What are the benefits of using binary format for storing logs? Is there possibility to force Erlang to use plain text files instead of binary ones? #4. What is the "index" file for? #5. Quote from Programming Erlang: --[Beginning of quote]------------------------------------------------- In a production environment, we are really interested only in errors and not progress or information reports, so we tell the error logger to report only errors. Without this setting, the system might get swamped with information and progress reports. Download elog4.config %% rotating log and errors [{sasl, [ %% minimise shell error logging {sasl_error_logger, false}, %% only report errors {errlog_type, error}, %% define the parameters of the rotating log %% the log file directory {error_logger_mf_dir,"/home/joe/error_logs" }, %% # bytes per logfile {error_logger_mf_maxbytes,10485760}, % 10 MB %% maximum number of {error_logger_mf_maxfiles, 10} ]}]. --[End of quote]------------------------------------------------- But using this config I see some progress reports: 3> rb:list(). No Type Process Date Time == ==== ======= ==== ==== 6 progress <0.30.0> 2008-10-10 03:39:59 5 progress <0.30.0> 2008-10-10 03:39:59 4 progress <0.30.0> 2008-10-10 03:39:59 3 progress <0.30.0> 2008-10-10 03:39:59 2 progress <0.23.0> 2008-10-10 03:39:59 1 error <0.24.0> 2008-10-10 03:40:20 ok What is wrong? -- Sergey. P.S. Sorry for the possible English mistakes in my letter =) From rec Fri Oct 10 17:56:30 2008 From: rec (Roger Critchlow) Date: Fri, 10 Oct 2008 09:56:30 -0600 Subject: [erlang-questions] write the ant simulation in Erlang? In-Reply-To: <859e91e70810092347x5903f7fdva3f44f6db99f916c@mail.gmail.com> References: <859e91e70810081456w244b1c9dh74e108325ae4135c@mail.gmail.com> <7D2420AE-BA6D-4EE4-85DD-CCB6C1723DBE@cs.otago.ac.nz> <859e91e70810082144v52c0998bi140a6116c67cf12a@mail.gmail.com> <859e91e70810082146k3457bd2evc813a51beda59989@mail.gmail.com> <3dbc6d1c0810091447ye7fbc56j9d7ee5f322dd1854@mail.gmail.com> <859e91e70810092347x5903f7fdva3f44f6db99f916c@mail.gmail.com> Message-ID: <66d1c98f0810100856r4d91c602lacb81c0b1fa9639e@mail.gmail.com> I think the world process is the right idea. It is supplying the semantics of the language runtime in Clojure which sorts out which speculative transactions are allowed to commit. Versioning of world state would need to restrict itself to the part of the world that the ant looked at, forcing a retry any time any part of the world had changed would be excessive. And I think that only moves resulting in ant-ant collisions need to be rejected -- that the rewards of moving might change between the time we make the decision and the time we enact the decision is unfortunate, but all too real. The clojure ants are making decisions based on a snapshot, too, and only retrying on collisions. Capturing the snapshot for display should be simple, just return the world_loop State. -- rec -- On Fri, Oct 10, 2008 at 12:47 AM, Brian Zhou wrote: > On Thu, Oct 9, 2008 at 2:47 PM, Robert Virding wrote: > > I haven't really checked the Clojure code that closely but it seems like > a > > reasonable problem. > > > > Do you know if it "turn based" or do the all the ants just move after > their > > own clocks in a parallel way? > The clojure implementation uses one thread for each ant. Each ant has > their own clock. > > > > > A first approximation would be to have one process per ant and one for > the > > world. The only problem would be handling atomic > > look-at-the-immediate-world-around-me-and-make-a-move. > > > Strictly speaking, the world state should be version'ed, the world > process should reject the move if the world has changed since the ant > looked, the ant process then should retry > look-decide-and-request-move. As an optimization, I guess the world > process can just check whether the FPA (food, pheromone, ant) value of > the target cell has changed. > > I wrote a rough first cut based on the above idea: > http://pastebin.ca/1224362 - It's not completed yet, TODO: > 1. pheromone evaporation > 2. initialization of the world, spawn world process, spawn ant processes > 3. scoring candidate cells > > Am I on the right track? > > > The really difficult bit is displaying it. :-) > > > I'm not there yet. > > Thanks, > > -Brian > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081010/510efa8e/attachment.html From sten.gruener Fri Oct 10 18:30:41 2008 From: sten.gruener (Stasik) Date: Fri, 10 Oct 2008 09:30:41 -0700 (PDT) Subject: [erlang-questions] FFI Interface - Limitation of the size of parameters Message-ID: Hello, I am quite new to Erland, and try to get some Erlang-C Communication. I found a tutorial at http://www.wagerlabs.com/blog/2008/02/erlang-ffi---in.html (which is a commented version of another tutorial, but it does not matter). Well, I was successful to compile the example and its pretty fine, BUT: I noticed that all exchanged parameters in port_driver.c are chars i.e.: - static void example_drv_output(ErlDrvData handle, char *buff, int bufflen) //here the input array consists of chars - driver_output(d->port, &res, 1); //here &res should point to a char, driver_output is a predefined function in erl_driver.h These limitations do not allow to send and receive any values which are bigger then 255 (and I do not want to split bigger numbers in bytes if there is a possibility to do it elegantly). Well, is there a known solution for that problem? I would like to have an int range. Cheers, Sten Gruener From erlang-questions_efine Fri Oct 10 18:47:08 2008 From: erlang-questions_efine (Edwin Fine) Date: Fri, 10 Oct 2008 12:47:08 -0400 Subject: [erlang-questions] Types and specs [WAS: [enhancement] string:split/2] In-Reply-To: <48EF3D78.2060306@cs.ntua.gr> References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> <48EF3D78.2060306@cs.ntua.gr> Message-ID: <6c2563b20810100947p4d6a638eh67d46c866fc9108a@mail.gmail.com> Question - trying to understand the spec, if I did the following: Eshell V5.6.4 (abort with ^G) 1> string:tokens([], "abc"). [] Does that violate the type specification, or does it allow for the return of an empty list? On Fri, Oct 10, 2008 at 7:33 AM, Kostis Sagonas wrote: > Richard O'Keefe wrote: > > > > Can anyone explain to me why > > > > -spec(tokens/2 :: (string(), string()) -> [[char(),...]]). > > > > doesn't mention "string()" on the right hand side of the arrow? > > There is no native string() type in Erlang, as we all well know. > > So, in the language ot types, string() is just an alias for the type > list(char()), which, for convenience, is typically written as [char()]. > This can include both the empty string "" == [] and a non-empty list > of characters, which is denoted [char(),...]. That's what the above > spec signifies: the resulting list consists of non-empty strings, which > is consistent with what string:tokens/2 actually returns. Hope this > explains things. > > On the other hand, I can see how this may look a bit strange to some and > have for a long time now pondered whether a non_empty_string() type > alias might be added to the list of built-in types. > > Kostis > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081010/eb457efe/attachment.html From kostis Fri Oct 10 18:57:28 2008 From: kostis (Kostis Sagonas) Date: Fri, 10 Oct 2008 19:57:28 +0300 Subject: [erlang-questions] Types and specs [WAS: [enhancement] string:split/2] In-Reply-To: <6c2563b20810100947p4d6a638eh67d46c866fc9108a@mail.gmail.com> References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> <48EF3D78.2060306@cs.ntua.gr> <6c2563b20810100947p4d6a638eh67d46c866fc9108a@mail.gmail.com> Message-ID: <48EF8978.1070304@cs.ntua.gr> Edwin Fine wrote: > Question - trying to understand the spec, if I did the following: > > Eshell V5.6.4 (abort with ^G) > 1> string:tokens([], "abc"). > [] > > Does that violate the type specification, or does it allow for the > return of an empty list? Note that the return type is specified as: [[char(),...]] i.e., a list of non-empty strings. The outer list can be empty or not. It's the strings inside it that cannot be empty. If the function returned a list of at least one non-empty string, it would have the following type instead: [[char(),...],...] If empty strings were allowed but there needed to be at least one of them, the return type would have been: [[char()],...] Hope this clears up the issue. Kostis > On Fri, Oct 10, 2008 at 7:33 AM, Kostis Sagonas > wrote: > > Richard O'Keefe wrote: > > > > Can anyone explain to me why > > > > -spec(tokens/2 :: (string(), string()) -> [[char(),...]]). > > > > doesn't mention "string()" on the right hand side of the arrow? > > There is no native string() type in Erlang, as we all well know. > > So, in the language ot types, string() is just an alias for the type > list(char()), which, for convenience, is typically written as [char()]. > This can include both the empty string "" == [] and a non-empty list > of characters, which is denoted [char(),...]. That's what the above > spec signifies: the resulting list consists of non-empty strings, which > is consistent with what string:tokens/2 actually returns. Hope this > explains things. > > On the other hand, I can see how this may look a bit strange to some and > have for a long time now pondered whether a non_empty_string() type > alias might be added to the list of built-in types. > > Kostis > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > > From erlang-questions_efine Fri Oct 10 19:00:30 2008 From: erlang-questions_efine (Edwin Fine) Date: Fri, 10 Oct 2008 13:00:30 -0400 Subject: [erlang-questions] Types and specs [WAS: [enhancement] string:split/2] In-Reply-To: <48EF8978.1070304@cs.ntua.gr> References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> <48EF3D78.2060306@cs.ntua.gr> <6c2563b20810100947p4d6a638eh67d46c866fc9108a@mail.gmail.com> <48EF8978.1070304@cs.ntua.gr> Message-ID: <6c2563b20810101000m15925507u64b100365d914052@mail.gmail.com> > > If the function returned a list of at least one non-empty string, it would > have the following type instead: > > [[char(),...],...] > > If empty strings were allowed but there needed to be at least one of them, > the return type would have been: > > [[char()],...] > > Hope this clears up the issue. > Yes, it does. Thanks for clarifying that. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081010/43a389cf/attachment.html From hasan.veldstra Fri Oct 10 21:14:38 2008 From: hasan.veldstra (Hasan Veldstra) Date: Fri, 10 Oct 2008 20:14:38 +0100 Subject: [erlang-questions] FFI Interface - Limitation of the size of parameters In-Reply-To: References: Message-ID: Check out the ei library: http://www.erlang.org/doc/man/ei.html You can use the term_to_binary function on the Erlang side on any term and then decode that in C using functions in ei. It works the other way round too. On 10 Oct 2008, at 17:30PM, Stasik wrote: > Hello, > > I am quite new to Erland, and try to get some Erlang-C Communication. > I found a tutorial at http://www.wagerlabs.com/blog/2008/02/erlang- > ffi---in.html > (which is a commented version of another tutorial, but it does not > matter). Well, I was successful to compile the example and its pretty > fine, BUT: I noticed that all exchanged parameters in port_driver.c > are chars i.e.: > - static void example_drv_output(ErlDrvData handle, char *buff, int > bufflen) //here the input array consists of chars > - driver_output(d->port, &res, 1); //here &res should point to a char, > driver_output is a predefined function in erl_driver.h > These limitations do not allow to send and receive any values which > are bigger then 255 (and I do not want to split bigger numbers in > bytes if there is a possibility to do it elegantly). > > Well, is there a known solution for that problem? I would like to have > an int range. > > Cheers, > Sten Gruener From greg.burri Fri Oct 10 21:54:17 2008 From: greg.burri (Greg Burri) Date: Fri, 10 Oct 2008 21:54:17 +0200 Subject: [erlang-questions] Chameneos.rednux micro benchmark Message-ID: <60ed8a460810101254s5e1f3a34rb79b644a0c6e4ea@mail.gmail.com> Hi, I'm very surprise to see the differences between these two same benchmarks on shootout.alioth.debian.org : 1) Quad core : http://shootout.alioth.debian.org/u64q/benchmark.php?test=chameneosredux&lang=hipe 2) Mono core : http://shootout.alioth.debian.org/u64/benchmark.php?test=chameneosredux&lang=hipe Here are the CPU times : 1) 2095.18 s 2) 37.03 s I try on my machine[1] with a) "-smp enable" and b) "-smp disable" : a) 47.863 s b) 18.285 Maybe It's not strange to see a such difference because of inter-cpu message passing. But the difference on shootout.alioth.debian.org is too large What should we do ? /Greg [1] : (Dual-Core AMD Opteron(tm) Processor 2212 HE, 2GHz) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081010/d0aa7017/attachment-0001.html From daniel.goertzen Fri Oct 10 21:59:03 2008 From: daniel.goertzen (Daniel Goertzen) Date: Fri, 10 Oct 2008 14:59:03 -0500 Subject: [erlang-questions] write the ant simulation in Erlang? In-Reply-To: <66d1c98f0810100856r4d91c602lacb81c0b1fa9639e@mail.gmail.com> References: <859e91e70810081456w244b1c9dh74e108325ae4135c@mail.gmail.com> <7D2420AE-BA6D-4EE4-85DD-CCB6C1723DBE@cs.otago.ac.nz> <859e91e70810082144v52c0998bi140a6116c67cf12a@mail.gmail.com> <859e91e70810082146k3457bd2evc813a51beda59989@mail.gmail.com> <3dbc6d1c0810091447ye7fbc56j9d7ee5f322dd1854@mail.gmail.com> <859e91e70810092347x5903f7fdva3f44f6db99f916c@mail.gmail.com> <66d1c98f0810100856r4d91c602lacb81c0b1fa9639e@mail.gmail.com> Message-ID: How about 1 process for each cell, but no processes for the ants. The ants exist as state inside each cell and as messages interrogating neighboring cells. I think you'll get nice fine-grained localized transactions this way. Dan. 2008/10/10 Roger Critchlow > I think the world process is the right idea. It is supplying the semantics > of the language runtime in Clojure which sorts out which speculative > transactions are allowed to commit. > > Versioning of world state would need to restrict itself to the part of the > world that the ant looked at, forcing a retry any time any part of the world > had changed would be excessive. > > And I think that only moves resulting in ant-ant collisions need to be > rejected -- that the rewards of moving might change between the time we make > the decision and the time we enact the decision is unfortunate, but all too > real. The clojure ants are making decisions based on a snapshot, too, and > only retrying on collisions. > > Capturing the snapshot for display should be simple, just return the > world_loop State. > > -- rec -- > > > > On Fri, Oct 10, 2008 at 12:47 AM, Brian Zhou wrote: > >> On Thu, Oct 9, 2008 at 2:47 PM, Robert Virding >> wrote: >> > I haven't really checked the Clojure code that closely but it seems like >> a >> > reasonable problem. >> > >> > Do you know if it "turn based" or do the all the ants just move after >> their >> > own clocks in a parallel way? >> The clojure implementation uses one thread for each ant. Each ant has >> their own clock. >> >> > >> > A first approximation would be to have one process per ant and one for >> the >> > world. The only problem would be handling atomic >> > look-at-the-immediate-world-around-me-and-make-a-move. >> > >> Strictly speaking, the world state should be version'ed, the world >> process should reject the move if the world has changed since the ant >> looked, the ant process then should retry >> look-decide-and-request-move. As an optimization, I guess the world >> process can just check whether the FPA (food, pheromone, ant) value of >> the target cell has changed. >> >> I wrote a rough first cut based on the above idea: >> http://pastebin.ca/1224362 - It's not completed yet, TODO: >> 1. pheromone evaporation >> 2. initialization of the world, spawn world process, spawn ant processes >> 3. scoring candidate cells >> >> Am I on the right track? >> >> > The really difficult bit is displaying it. :-) >> > >> I'm not there yet. >> >> Thanks, >> >> -Brian >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions >> http://www.erlang.org/mailman/listinfo/erlang-questions >> > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081010/7aac75dd/attachment.html From rick.richardson Fri Oct 10 22:38:46 2008 From: rick.richardson (Rick R) Date: Fri, 10 Oct 2008 16:38:46 -0400 Subject: [erlang-questions] write the ant simulation in Erlang? In-Reply-To: References: <859e91e70810081456w244b1c9dh74e108325ae4135c@mail.gmail.com> <7D2420AE-BA6D-4EE4-85DD-CCB6C1723DBE@cs.otago.ac.nz> <859e91e70810082144v52c0998bi140a6116c67cf12a@mail.gmail.com> <859e91e70810082146k3457bd2evc813a51beda59989@mail.gmail.com> <3dbc6d1c0810091447ye7fbc56j9d7ee5f322dd1854@mail.gmail.com> <859e91e70810092347x5903f7fdva3f44f6db99f916c@mail.gmail.com> <66d1c98f0810100856r4d91c602lacb81c0b1fa9639e@mail.gmail.com> Message-ID: <9810b81b0810101338i1b5018e2p5e36bff85acbfe3c@mail.gmail.com> 2008/10/10 Daniel Goertzen > How about 1 process for each cell, but no processes for the ants. The ants > exist as state inside each cell and as messages interrogating neighboring > cells. I think you'll get nice fine-grained localized transactions this > way. > > Dan. > > Using that method, I think you'll still have the same issue with transactions. For instance: if two cells decide to move their ant to the same adjacent cell, you will have the same conflict and one ant will have to be rolled back. It may not even be more efficient message-wise because instead of the ant sending a message to an adjacent cell, the cell simply sends the same message to the adjacent cell on behalf of the ant. Of course we could go existentialist and say that there is no board except what the ants perceive, and since they can only see one square in any direction, that would imply that there is 1 process for each ant and no process for a board (or any data for that matter). This would mean that if there are no ants on a section of board it would cease to exist. The only way to reconstitute it would be to mathematically prove that it exists. e.g. The ant was at 5,5 and moved 3 east, 8 < 64, therefore, the board exists. One could extend this method with a Paxos algorithm so that the ants could achieve consensus as to the existence of Board. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081010/97557102/attachment.html From kevin Fri Oct 10 22:47:20 2008 From: kevin (Kevin Scaldeferri) Date: Fri, 10 Oct 2008 13:47:20 -0700 Subject: [erlang-questions] Chameneos.rednux micro benchmark In-Reply-To: <60ed8a460810101254s5e1f3a34rb79b644a0c6e4ea@mail.gmail.com> References: <60ed8a460810101254s5e1f3a34rb79b644a0c6e4ea@mail.gmail.com> Message-ID: On Oct 10, 2008, at 12:54 PM, Greg Burri wrote: > Hi, > I'm very surprise to see the differences between these two same > benchmarks on shootout.alioth.debian.org : > 1) Quad core : http://shootout.alioth.debian.org/u64q/benchmark.php?test=chameneosredux&lang=hipe > 2) Mono core : http://shootout.alioth.debian.org/u64/benchmark.php?test=chameneosredux&lang=hipe > > Here are the CPU times : > 1) 2095.18 s > 2) 37.03 s > > I try on my machine[1] with a) "-smp enable" and b) "-smp disable" : > a) 47.863 s > b) 18.285 > > Maybe It's not strange to see a such difference because of inter-cpu > message passing. But the difference on shootout.alioth.debian.org is > too large > What should we do ? Are you using HiPE? There's some chance that could explain some of the relative difference. I don't think message passing is the issue. I suspect it's lack of process affinity. The chameneos processes are likely getting bounced around between schedulers constantly. In the short term, I'm not sure what can be done other than requesting the benchmark be run with '-S 1', which really kinda defeats the purpose. It would be nice to have a different solution, as I agree that this situation is pretty embarrassing. This task is such a natural for the actor-model and Erlang; it's a shame the performance ends up being so poor. -k -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081010/498c0537/attachment.html From dmercer Fri Oct 10 23:43:00 2008 From: dmercer (David Mercer) Date: Fri, 10 Oct 2008 16:43:00 -0500 Subject: [erlang-questions] write the ant simulation in Erlang? In-Reply-To: <9810b81b0810101338i1b5018e2p5e36bff85acbfe3c@mail.gmail.com> References: <859e91e70810081456w244b1c9dh74e108325ae4135c@mail.gmail.com><7D2420AE-BA6D-4EE4-85DD-CCB6C1723DBE@cs.otago.ac.nz><859e91e70810082144v52c0998bi140a6116c67cf12a@mail.gmail.com><859e91e70810082146k3457bd2evc813a51beda59989@mail.gmail.com><3dbc6d1c0810091447ye7fbc56j9d7ee5f322dd1854@mail.gmail.com><859e91e70810092347x5903f7fdva3f44f6db99f916c@mail.gmail.com><66d1c98f0810100856r4d91c602lacb81c0b1fa9639e@mail.gmail.com> <9810b81b0810101338i1b5018e2p5e36bff85acbfe3c@mail.gmail.com> Message-ID: Actually Danny G's approach has merit. Ant on square A wants to move to square B. The messages passed are quite simple: 1. A: B ! {A, 'I have an ant who wants to move to you'} 2. B: Either: a. A ! 'Your ant moved here successfully' b. A ! 'No can do, mate; I'm already occupied' In the case of 2a, square A marks itself vacant and can now respond with its own 'Your ant moved here successfully' message when another square requests passage for its ant. In case of 2b, square A tries another square. DBM _____ From: erlang-questions-bounces [mailto:erlang-questions-bounces] On Behalf Of Rick R Sent: Friday, October 10, 2008 15:39 To: Erlang-Questions (E-mail) Subject: Re: [erlang-questions] write the ant simulation in Erlang? 2008/10/10 Daniel Goertzen How about 1 process for each cell, but no processes for the ants. The ants exist as state inside each cell and as messages interrogating neighboring cells. I think you'll get nice fine-grained localized transactions this way. Dan. Using that method, I think you'll still have the same issue with transactions. For instance: if two cells decide to move their ant to the same adjacent cell, you will have the same conflict and one ant will have to be rolled back. It may not even be more efficient message-wise because instead of the ant sending a message to an adjacent cell, the cell simply sends the same message to the adjacent cell on behalf of the ant. Of course we could go existentialist and say that there is no board except what the ants perceive, and since they can only see one square in any direction, that would imply that there is 1 process for each ant and no process for a board (or any data for that matter). This would mean that if there are no ants on a section of board it would cease to exist. The only way to reconstitute it would be to mathematically prove that it exists. e.g. The ant was at 5,5 and moved 3 east, 8 < 64, therefore, the board exists. One could extend this method with a Paxos algorithm so that the ants could achieve consensus as to the existence of Board. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081010/35103f7e/attachment-0001.html From rick.richardson Sat Oct 11 00:37:47 2008 From: rick.richardson (Rick R) Date: Fri, 10 Oct 2008 18:37:47 -0400 Subject: [erlang-questions] write the ant simulation in Erlang? In-Reply-To: References: <859e91e70810081456w244b1c9dh74e108325ae4135c@mail.gmail.com> <7D2420AE-BA6D-4EE4-85DD-CCB6C1723DBE@cs.otago.ac.nz> <859e91e70810082144v52c0998bi140a6116c67cf12a@mail.gmail.com> <859e91e70810082146k3457bd2evc813a51beda59989@mail.gmail.com> <3dbc6d1c0810091447ye7fbc56j9d7ee5f322dd1854@mail.gmail.com> <859e91e70810092347x5903f7fdva3f44f6db99f916c@mail.gmail.com> <66d1c98f0810100856r4d91c602lacb81c0b1fa9639e@mail.gmail.com> <9810b81b0810101338i1b5018e2p5e36bff85acbfe3c@mail.gmail.com> Message-ID: <9810b81b0810101537w5c0e422fn81c4111dc585339b@mail.gmail.com> You're right. I didn't think it through at all. Better than decreasing the amount of messages, it avoids having to transact (or resolve conflicts) at all. The cell can have three states, empty, full, or pending. Pending would be that it is waiting for a response from an adjacent cell on whether it's ant can move there. It would simply delay any of its own responses until receiving a response from it's suitor. One could argue for a fourth state which is empty-but-expecting. But if an ant is guaranteed to travel to your location once you've agreed to let it, then this state is as good as full. Not treating the ant as its own actor does take the fun (and the expense) out it. On Fri, Oct 10, 2008 at 5:43 PM, David Mercer wrote: > Actually Danny G's approach has merit. Ant on square A wants to move to > square B. The messages passed are quite simple: > > > > 1. A: B ! {A, 'I have an ant who wants to move to you'} > 2. B: Either: > 1. A ! 'Your ant moved here successfully' > 2. A ! 'No can do, mate; I'm already occupied' > > > > In the case of 2a, square A marks itself vacant and can now respond with > its own 'Your ant moved here successfully' message when another square > requests passage for its ant. In case of 2b, square A tries another square. > > > > DBM > > > > > > > ------------------------------ > > *From:* erlang-questions-bounces [mailto: > erlang-questions-bounces] *On Behalf Of *Rick R > *Sent:* Friday, October 10, 2008 15:39 > *To:* Erlang-Questions (E-mail) > *Subject:* Re: [erlang-questions] write the ant simulation in Erlang? > > > > > > 2008/10/10 Daniel Goertzen > > How about 1 process for each cell, but no processes for the ants. The ants > exist as state inside each cell and as messages interrogating neighboring > cells. I think you'll get nice fine-grained localized transactions this > way. > > Dan. > > > Using that method, I think you'll still have the same issue with > transactions. For instance: if two cells decide to move their ant to the > same adjacent cell, you will have the same conflict and one ant will have to > be rolled back. > It may not even be more efficient message-wise because instead of the ant > sending a message to an adjacent cell, the cell simply sends the same > message to the adjacent cell on behalf of the ant. > > Of course we could go existentialist and say that there is no board except > what the ants perceive, and since they can only see one square in any > direction, that would imply that there is 1 process for each ant and no > process for a board (or any data for that matter). This would mean that if > there are no ants on a section of board it would cease to exist. The only > way to reconstitute it would be to mathematically prove that it exists. e.g. > The ant was at 5,5 and moved 3 east, 8 < 64, therefore, the board exists. > > One could extend this method with a Paxos algorithm so that the ants could > achieve consensus as to the existence of Board. > > -- "Have more than thou showest, Speak less than thou knowest, Lend less than thou owest, Ride more than thou goest." -- The Fool to King Lear -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081010/4045ad6e/attachment.html From erlang-questions_efine Sat Oct 11 01:19:14 2008 From: erlang-questions_efine (Edwin Fine) Date: Fri, 10 Oct 2008 19:19:14 -0400 Subject: [erlang-questions] Chameneos.rednux micro benchmark In-Reply-To: References: <60ed8a460810101254s5e1f3a34rb79b644a0c6e4ea@mail.gmail.com> Message-ID: <6c2563b20810101619m5c373e1bhe9d0aad36fc2a06d@mail.gmail.com> It was run with HiPE. It's mentioned on the page that has the Erlang code. I was curious so I ran it on my configuration (Ubuntu 8.04 x86_64, 2.4GHz Q6600, 8GB RAM, Erlang R12B-4). Here's the bottom line. *When I ran it with -smp disable there was a* *monumentally huge* *(91.8x) * *performance boost* *over when I ran it with smp enabled*. That was without HiPE. Adding HiPE speeded the SMP version up by about 20% or so. The performance difference between the non-SMP HiPE and non-HiPE versions was about 80x. # *SMP without HiPE *$ time /usr/local/bin/erl +K true -noshell -run chameneosredux main 6000000 *real 11m24.231s *user 20m25.933s sys 1m49.315s # *SMP with HiPE * $ time /usr/local/bin/erl +K true -noshell -run chameneosredux main 6000000 *real 9m19.138s* user 16m28.374s sys 1m49.899s # *SMP disabled, without HiPE *$ time /usr/local/bin/erl -smp disable +K true -noshell -run chameneosredux main 6000000 *real 0m7.451s *user 0m7.404s sys 0m0.048s # *SMP disabled, with HiPE *$ time /usr/local/bin/erl -smp disable +K true -noshell -run chameneosredux main 6000000 *real 0m6.970s *user 0m6.864s sys 0m0.104s So if it's not CPU-bound (60% idle), and it's not memory capacity bound (virtual memory usage only 78MB), and it's not disk or network I/O bound, what is it? A run of vmstat showed a minimum of about *15,000 context switches per second* and often more. Without the program running, there were *only about 500 or so per second*. procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu---- r b swpd free buff cache si so bi bo in cs us sy id wa 6 0 371656 651900 646988 967940 0 0 0 0 67 15781 44 1 55 0 3 0 371656 651900 646992 967936 0 0 0 4 179 18291 44 2 54 0 1 0 371656 651900 646992 967940 0 0 0 0 61 28605 44 2 54 0 2 0 371656 651892 646992 967940 0 0 0 0 156 15751 42 1 57 0 3 0 371656 651900 646992 967940 0 0 0 0 61 78329 47 6 48 0 3 0 371656 651776 646992 967940 0 0 0 0 156 15081 43 1 56 0 3 0 371656 651776 646992 967940 0 0 0 0 61 15800 44 1 55 0 2 0 371656 651776 646996 967936 0 0 0 4 157 15393 44 1 55 0 2 0 371656 651760 646996 967940 0 0 0 0 62 16251 46 1 53 0 2 0 371656 651776 646996 967940 0 0 0 0 156 35213 43 4 53 0 I ran again with vmstat and -*smp disabled*. vmstat showed *no noticable difference* in the cs column *when the program was running compared to when it was not*: 0 0 371656 707156 624840 947328 0 0 0 28 110 453 0 0 100 0 0 0 371656 707148 624840 947328 0 0 0 0 285 775 0 0 99 0 0 0 371656 707140 624840 947328 0 0 0 0 102 537 0 0 100 0 0 0 371656 707148 624840 947328 0 0 0 0 172 597 0 0 100 0 0 0 371656 707148 624840 947328 0 0 0 0 113 532 0 0 100 0 1 0 371656 700460 624840 947328 32 0 32 0 204 1290 24 1 75 0 1 0 371656 700436 624840 947328 0 0 0 0 71 655 28 0 72 0 1 0 371656 700412 624844 947324 0 0 0 44 302 994 26 0 74 0 1 0 371656 700436 624844 947328 0 0 0 0 98 520 26 0 74 0 1 0 371656 700436 624844 947328 0 0 0 0 156 558 25 0 75 0 1 0 371656 700428 624844 947328 0 0 0 0 76 431 25 0 74 0 Tentative conclusion: this benchmark makes SMP Erlang do an excessive number of context switches. Is that because it is jumping between cores, or because of inter-process communication between cores? I can't answer that fully, but I can see what happens if we retrict it to one core using one VM. And the answer is: *vmstat shows that using taskset and +S 1, the context switches go down to about the same level as if you were not running with SMP *. It's still about 3x slower than -smp disable, though, but orders of magnitude faster than using all processors with SMP. * # SMP, Without HiPE, one scheduler, affinitied to CPU 2* $ time taskset -c 2 /usr/local/bin/erl +S 1 -noshell -noinput -run chameneosredux main 6000000 *real 0m24.296s* user 0m24.270s sys 0m0.004s Last one. What about using +K true to user kernel poll? No significant difference. *real 0m24.006s* user 0m23.998s sys 0m0.012s I tried capturing the output of various runs using strace but it's going to take me a while to interpret the results (if I can even do that) and rerun it until it makes sense. I don't know if it makes sense to try to use strace with Erlang. I'll have to do some Googling. Regards, Edwin Fine 2008/10/10 Kevin Scaldeferri > > On Oct 10, 2008, at 12:54 PM, Greg Burri wrote: > > Hi, > I'm very surprise to see the differences between these two same benchmarks > on shootout.alioth.debian.org : > 1) Quad core : > http://shootout.alioth.debian.org/u64q/benchmark.php?test=chameneosredux&lang=hipe > 2) Mono core : > http://shootout.alioth.debian.org/u64/benchmark.php?test=chameneosredux&lang=hipe > > Here are the CPU times : > 1) 2095.18 s > 2) 37.03 s > > I try on my machine[1] with a) "-smp enable" and b) "-smp disable" : > a) 47.863 s > b) 18.285 > > Maybe It's not strange to see a such difference because of inter-cpu > message passing. But the difference on shootout.alioth.debian.org is too > large > What should we do ? > > > Are you using HiPE? There's some chance that could explain some of the > relative difference. > > I don't think message passing is the issue. I suspect it's lack of process > affinity. The chameneos processes are likely getting bounced around between > schedulers constantly. > > In the short term, I'm not sure what can be done other than requesting the > benchmark be run with '-S 1', which really kinda defeats the purpose. It > would be nice to have a different solution, as I agree that this situation > is pretty embarrassing. This task is such a natural for the actor-model and > Erlang; it's a shame the performance ends up being so poor. > > -k > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081010/076528b9/attachment-0001.html From dmercer Sat Oct 11 06:12:05 2008 From: dmercer (David Mercer) Date: Fri, 10 Oct 2008 23:12:05 -0500 Subject: [erlang-questions] write the ant simulation in Erlang? In-Reply-To: <9810b81b0810101537w5c0e422fn81c4111dc585339b@mail.gmail.com> References: <859e91e70810081456w244b1c9dh74e108325ae4135c@mail.gmail.com> <859e91e70810082144v52c0998bi140a6116c67cf12a@mail.gmail.com> <859e91e70810082146k3457bd2evc813a51beda59989@mail.gmail.com> <3dbc6d1c0810091447ye7fbc56j9d7ee5f322dd1854@mail.gmail.com> <859e91e70810092347x5903f7fdva3f44f6db99f916c@mail.gmail.com> <66d1c98f0810100856r4d91c602lacb81c0b1fa9639e@mail.gmail.com> <9810b81b0810101338i1b5018e2p5e36bff85acbfe3c@mail.gmail.com> <9810b81b0810101537w5c0e422fn81c4111dc585339b@mail.gmail.com> Message-ID: Actually, I'd just have two states: ant and antless. Your pending state could result in deadlocks. David On Fri, Oct 10, 2008 at 5:37 PM, Rick R wrote: > You're right. I didn't think it through at all. > Better than decreasing the amount of messages, it avoids having to transact > (or resolve conflicts) at all. > The cell can have three states, empty, full, or pending. Pending would be > that it is waiting for a response from an adjacent cell on whether it's ant > can move there. It would simply delay any of its own responses until > receiving a response from it's suitor. > > One could argue for a fourth state which is empty-but-expecting. But if an > ant is guaranteed to travel to your location once you've agreed to let it, > then this state is as good as full. > > Not treating the ant as its own actor does take the fun (and the expense) > out it. > > On Fri, Oct 10, 2008 at 5:43 PM, David Mercer wrote: > >> Actually Danny G's approach has merit. Ant on square A wants to move to >> square B. The messages passed are quite simple: >> >> >> >> 1. A: B ! {A, 'I have an ant who wants to move to you'} >> 2. B: Either: >> 1. A ! 'Your ant moved here successfully' >> 2. A ! 'No can do, mate; I'm already occupied' >> >> >> >> In the case of 2a, square A marks itself vacant and can now respond with >> its own 'Your ant moved here successfully' message when another square >> requests passage for its ant. In case of 2b, square A tries another square. >> >> >> >> DBM >> >> >> >> >> >> >> ------------------------------ >> >> *From:* erlang-questions-bounces [mailto: >> erlang-questions-bounces] *On Behalf Of *Rick R >> *Sent:* Friday, October 10, 2008 15:39 >> *To:* Erlang-Questions (E-mail) >> *Subject:* Re: [erlang-questions] write the ant simulation in Erlang? >> >> >> >> >> >> 2008/10/10 Daniel Goertzen >> >> How about 1 process for each cell, but no processes for the ants. The >> ants exist as state inside each cell and as messages interrogating >> neighboring cells. I think you'll get nice fine-grained localized >> transactions this way. >> >> Dan. >> >> >> Using that method, I think you'll still have the same issue with >> transactions. For instance: if two cells decide to move their ant to the >> same adjacent cell, you will have the same conflict and one ant will have to >> be rolled back. >> It may not even be more efficient message-wise because instead of the ant >> sending a message to an adjacent cell, the cell simply sends the same >> message to the adjacent cell on behalf of the ant. >> >> Of course we could go existentialist and say that there is no board except >> what the ants perceive, and since they can only see one square in any >> direction, that would imply that there is 1 process for each ant and no >> process for a board (or any data for that matter). This would mean that if >> there are no ants on a section of board it would cease to exist. The only >> way to reconstitute it would be to mathematically prove that it exists. e.g. >> The ant was at 5,5 and moved 3 east, 8 < 64, therefore, the board exists. >> >> One could extend this method with a Paxos algorithm so that the ants could >> achieve consensus as to the existence of Board. >> >> > > > -- > "Have more than thou showest, > Speak less than thou knowest, > Lend less than thou owest, > Ride more than thou goest." > -- The Fool to King Lear > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081010/2ae33eed/attachment.html From steven.charles.davis Sat Oct 11 11:36:24 2008 From: steven.charles.davis (Steve Davis) Date: Sat, 11 Oct 2008 02:36:24 -0700 (PDT) Subject: [erlang-questions] Why is query a reserved word Message-ID: I notice that query is a reserved word in erlang - anyone know why? It's the first/most obvious function name you'd choose when dealing with a data store, so i'm interested in why it's reserved... From steven.charles.davis Sat Oct 11 11:46:55 2008 From: steven.charles.davis (Steve Davis) Date: Sat, 11 Oct 2008 04:46:55 -0500 Subject: [erlang-questions] Just curious - why is "query" a reserved word? Message-ID: <48F0760F.5010101@gmail.com> It's one of the most obvious choices of function name when dealing with persistent storage - and I notice that e.g. erlyweb has used q(), q1(), etc instead probably *because* query is a reserved word. So I'm curious as to why it is reserved? /s From Lennart.Ohman Sat Oct 11 12:35:54 2008 From: Lennart.Ohman (=?iso-8859-1?Q?Lennart_=D6hman?=) Date: Sat, 11 Oct 2008 12:35:54 +0200 Subject: [erlang-questions] Why is query a reserved word In-Reply-To: References: Message-ID: Hi, it was used in defining a Mnemosyne query - a now obsoleted Mnesia query language. Check R11B documentation if you are interested in learning more about Mnemosyne. Best Regards Lennart ________________________________________ From: erlang-questions-bounces [erlang-questions-bounces] On Behalf Of Steve Davis [steven.charles.davis] Sent: Saturday, October 11, 2008 11:36 AM To: erlang-questions Subject: [erlang-questions] Why is query a reserved word I notice that query is a reserved word in erlang - anyone know why? It's the first/most obvious function name you'd choose when dealing with a data store, so i'm interested in why it's reserved... _______________________________________________ erlang-questions mailing list erlang-questions http://www.erlang.org/mailman/listinfo/erlang-questions From steven.charles.davis Sat Oct 11 12:53:02 2008 From: steven.charles.davis (Steve Davis) Date: Sat, 11 Oct 2008 05:53:02 -0500 Subject: [erlang-questions] Why is query a reserved word In-Reply-To: References: Message-ID: <48F0858E.8050501@gmail.com> Thanks, Lennart - I figured there must be some historical reason. Umm... anyone know if there's a chance that it will be "unreserved" in the future? /s Lennart ?hman wrote: > Hi, > it was used in defining a Mnemosyne query - a now obsoleted Mnesia query language. > Check R11B documentation if you are interested in learning more about Mnemosyne. > > Best Regards > Lennart > > ________________________________________ > From: erlang-questions-bounces [erlang-questions-bounces] On Behalf Of Steve Davis [steven.charles.davis] > Sent: Saturday, October 11, 2008 11:36 AM > To: erlang-questions > Subject: [erlang-questions] Why is query a reserved word > > I notice that query is a reserved word in erlang - anyone know why? > It's the first/most obvious function name you'd choose when dealing > with a data store, so i'm interested in why it's reserved... > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From erlang-questions_efine Sat Oct 11 18:21:03 2008 From: erlang-questions_efine (Edwin Fine) Date: Sat, 11 Oct 2008 12:21:03 -0400 Subject: [erlang-questions] What erlc flags are needed to compile native (HiPE) to run on smp-disabled runtime? Message-ID: <6c2563b20810110921n28ff218p7707902cf0b29b5d@mail.gmail.com> To generate native code for smp-enabled runtime using erlc is easy. I can't seem to make it happen for smp disabled runtime. If I start up Erlang with -smp disable and compile from within Erlang, then it does what I want (creates a natively-compiled beam for non-smp use). $ erl -smp disable 1> c(mymodule, [native, {hipe, o3}]) {ok,mymodule} 8> But this is very inconvenient if a build system is created that relies on erlc. Is there a better way? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081011/d52b9d29/attachment.html From kevin Sat Oct 11 18:59:27 2008 From: kevin (Kevin Scaldeferri) Date: Sat, 11 Oct 2008 09:59:27 -0700 Subject: [erlang-questions] Fwd: Chameneos.rednux micro benchmark References: Message-ID: [sigh... hit Reply instead of Reply All] Begin forwarded message: > From: Kevin Scaldeferri > Date: October 10, 2008 6:31:27 PM PDT > To: "Edwin Fine" > Subject: Re: [erlang-questions] Chameneos.rednux micro benchmark > > > On Oct 10, 2008, at 4:19 PM, Edwin Fine wrote: > >> It was run with HiPE. It's mentioned on the page that has the >> Erlang code. > > I was actually asking about when you ran it. I did know that the > benchmark site uses HiPE. > >> >> A run of vmstat showed a minimum of about 15,000 context switches >> per second and often more. Without the program running, there were >> only about 500 or so per second. >> ... >> >> I ran again with vmstat and -smp disabled. vmstat showed no >> noticable difference in the cs column when the program was running >> compared to when it was not: >> >> ... >> >> Tentative conclusion: this benchmark makes SMP Erlang do an >> excessive number of context switches. Is that because it is jumping >> between cores, or because of inter-process communication between >> cores? I can't answer that fully, but I can see what happens if we >> retrict it to one core using one VM. > > This is not all that surprising. Consider the part of the benchmark > where there are 3 chameneos participating. Each of them, and the > parent, will likely end up on their own scheduler (on quad-core). > They all send a message then go to sleep. The parent receives the > messages, processes some, goes to sleep. Children wake up, get > messages, send message, go to sleep. Repeat. You can see that for > much of the time, many of the schedules have nothing to do, and > their threads may be switched out. > > Without SMP, all the Erlang processes run in the same scheduler > thread, and there is always work to be done, so no or few context > switches. > > Of course, for the portion with 10 chameneos, there is more often > work that can be done, but maybe still not enough to saturate all > the cores all the time. > >> >> >> So if it's not CPU-bound (60% idle), and it's not memory capacity >> bound (virtual memory usage only 78MB), and it's not disk or >> network I/O bound, what is it? > > a) as explained above, there are synchronization requirements as > part of the game that may make it difficult to saturate all the CPUs > > b) I also speculated that migrating processes from one thread (core) > to another may be significant. I'm not really sure where to look in > the OS stats to find evidence to support this. (I guess you'd want > to see if the memory bus is saturated.) > > > > I should also point out that it seems like there is either a > significant different between Erlang running on 2 and 4 cores, or > between the chip architectures themselves. Running parallel > versions of other benchmarks on my 2-core hardware, I usually find > that the total CPU time used is only slightly higher than a single- > process version. However, on the Alioth 4-core hardware, the total > CPU usage is about double. (Look at the two Erlang version for > binary-trees and mandelbrot). I am inclined to think Erlang is to > blame, if only because the Haskell entries don't show the same > behavior. > > > > -kevin > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081011/c24e24be/attachment.html From ulf Sat Oct 11 19:08:40 2008 From: ulf (Ulf Wiger) Date: Sat, 11 Oct 2008 19:08:40 +0200 Subject: [erlang-questions] Just curious - why is "query" a reserved word? In-Reply-To: <48F0760F.5010101@gmail.com> References: <48F0760F.5010101@gmail.com> Message-ID: <8209f740810111008u20725ff5p84e999856210073b@mail.gmail.com> It was used by mnemosyne list comprehensions. BR, Ulf W 2008/10/11, Steve Davis : > It's one of the most obvious choices of function name when dealing with > persistent storage - and I notice that e.g. erlyweb has used q(), q1(), > etc instead probably *because* query is a reserved word. So I'm curious > as to why it is reserved? > > /s > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From erlang-questions_efine Sat Oct 11 21:13:06 2008 From: erlang-questions_efine (Edwin Fine) Date: Sat, 11 Oct 2008 15:13:06 -0400 Subject: [erlang-questions] Lots of questions about error_logger In-Reply-To: <3bff71aa0810100809w1b5282dfhd7bd06876f255605@mail.gmail.com> References: <3bff71aa0810100809w1b5282dfhd7bd06876f255605@mail.gmail.com> Message-ID: <6c2563b20810111213h13ceae5fy11e588323b10e3d0@mail.gmail.com> On Fri, Oct 10, 2008 at 11:09 AM, Sergey A. wrote: > Hello. > > In the first place, sorry for several different questions placed in > one letter. I know it's something wearily to answer a list of > questions. > > I tried using error_logger as a tool for handling error reports and > I've came across some oddities: > > #1. Is there a way to set SASL options (I'm about sasl_error_logger, > errlog_type etc) from the Erlang code at runtime without using a > .config file + the "-config" argument? Possibly, but I don't know how. I just want to give an end user > only one config file to edit and use values from that to setup SASL. You can put the sasl config along with other application configs. You can pass application environment variables in this way to your own apps. This usually goes into a file named sys.config, which is expected (or at least standard) if you use Erlang release management (see http://www.erlang.org/doc/man/systools.html). [ {sasl, [ {sasl_error_logger, {file, "/data/shg/log_base/shg.sasl_log"}} ]}, {myapp1, [ {myappvar1, "value1"}, {myappvar2, value2} ] } ]. %% <-- dot and whitespace Remember to have a dot and whitespace at end of file as shown above. > #2. The following is from the "Programming Erlang": > > --[Beginning of quote]------------------------------------------------- > The next configuration file lists error reports in the shell, and a copy of > everything reported in the shell is also made to a file: > > %% single text file - minimal tty > [{sasl, [ > %% All reports go to this file > {sasl_error_logger, {file, "/home/joe/error_logs/THELOG" }} > ]}]." > --[End of quote]------------------------------------------------- > > I replaced the path to just "THELOG" and then run the shell: > > --[Beginning of erl > session]------------------------------------------------- > erl -boot start_sasl -config elog2.config > > Erlang (BEAM) emulator version 5.6.3 [source] [smp:2] > [async-threads:0] [hipe] [kernel-poll:false] > > Eshell V5.6.3 (abort with ^G) > 1> error_logger:error_msg("foobar~n"). > ok > > =ERROR REPORT==== 10-Oct-2008::03:19:38 === > foobar > 2> error_logger:error_report("foobar\n"). > > =ERROR REPORT==== 10-Oct-2008::03:21:05 === > foobar > > ok > 3> > User switch command > --> q > --[End of erl session]------------------------------------------------- > > But after all, THELOG doesn't contain any string related to my > foobar-errors! Just only progress reports! Why does this happen? > The standard error log handler in SASL only logs supervisor reports, crashes and progress reports. Take a look at http://www.erlang.org/doc/apps/sasl/index.html, from which the following was extracted: Error Logger Event Handlers The following error logger event handlers are defined in the SASL application. sasl_report_tty_h Formats and writes *supervisor reports*, *crash reports*and *progress reports* to stdio. sasl_report_file_h Formats and writes *supervisor reports*, *crash report*and *progress report* to a single file. error_logger_mf_h This error logger writes *all* events sent to the error logger to disk. It installs the log_mf_h event handler in the error_loggerprocess.You need to configure the error_logger_mf_h to get what you have logged, for example: [ { sasl, [ % All supervisor, crash, and progress reports go to this file {sasl_error_logger, {file, "/tmp/error_logs/sasl_log" }}, % And to these files, too {error_logger_mf_dir, "/tmp/error_logs"}, {error_logger_mf_maxbytes, 10000000}, {error_logger_mf_maxfiles, 10} ] } ]. > #3. If I decide to use rotating of logs, those logs will be written in > binary format. What are the benefits of using binary format for > storing logs? The binary format files are very fast to write and more compact than ASCII logs. However, they are much less convenient to browse. I think many people use ASCII logs, but you have to be careful and not flood your system with logs. > Is there possibility to force Erlang to use plain text > files instead of binary ones? > Yes, but you have to provide your own error logger callback module. Fortunately, there is at least one I know of that is publicly available, in Jungerl. You'll need to get these: http://jungerl.cvs.sourceforge.net/viewvc/jungerl/jungerl/lib/msc/src/disk_log_h.erl?revision=1.2&view=markup http://jungerl.cvs.sourceforge.net/viewvc/jungerl/jungerl/lib/msc/src/logger.erl?revision=1.2&view=markup The files contain documentation on how to install and use these. I've used them for quite a while with no problems. > > #4. What is the "index" file for? > I dunno. I think it's for the wrap logs, to ell the logger which number to use next. So if you are running 10 logs, they start off at 1. Once they get to 10, they start at 1 again. I think the index file contains the next index. Let's find out. 1> file:read_file("index"). {ok,<<2>>} 2> Yes, looks like it's just a binary integer that has the next wrap index. > > #5. Quote from Programming Erlang: > --[Beginning of quote]------------------------------------------------- > In a production environment, we are really interested only in errors and > not progress or information reports, so we tell the error logger to report > only errors. Without this setting, the system might get swamped with > information and progress reports. > Download elog4.config > %% rotating log and errors > [{sasl, [ > %% minimise shell error logging > {sasl_error_logger, false}, > %% only report errors > {errlog_type, error}, > %% define the parameters of the rotating log > %% the log file directory > {error_logger_mf_dir,"/home/joe/error_logs" }, > %% # bytes per logfile > {error_logger_mf_maxbytes,10485760}, % 10 MB > %% maximum number of > {error_logger_mf_maxfiles, 10} > ]}]. > --[End of quote]------------------------------------------------- > > But using this config I see some progress reports: > > 3> rb:list(). > No Type Process Date Time > == ==== ======= ==== ==== > 6 progress <0.30.0> 2008-10-10 03:39:59 > 5 progress <0.30.0> 2008-10-10 03:39:59 > 4 progress <0.30.0> 2008-10-10 03:39:59 > 3 progress <0.30.0> 2008-10-10 03:39:59 > 2 progress <0.23.0> 2008-10-10 03:39:59 > 1 error <0.24.0> 2008-10-10 03:40:20 > ok > > What is wrong? When you put in {sasl_error_logger, false}, the {errlog_type, error} is ignored because it pertains only to the sasl_error_logger file. If {sasl_error_logger, {file, "foo.bar"}} was specified, then {errlog_type, error} would mean, "Put only errors into foo.bar". It has no control over what goes into the error_logger_mf binary files. It appears (AFAIK) that SASL will always log progress reports and crash reports to the binary file(s) controlled by error_logger_mf, if they are configured, but because you specified {sasl_error_logger, false} they are not being duplicated into a separate SASL ASCII log file, e.g. "foo.bar". Hope this makes sense. P.S. Sorry for the possible English mistakes in my letter =) Your English is pretty good, actually. Hope this helps. Edwin -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081011/a6ea3b21/attachment-0001.html From igouy2 Sat Oct 11 23:00:09 2008 From: igouy2 (Isaac Gouy) Date: Sat, 11 Oct 2008 14:00:09 -0700 (PDT) Subject: [erlang-questions] Chameneos.rednux micro benchmark Message-ID: <1688.88913.qm@web65409.mail.ac4.yahoo.com> On Oct 11, 2008, Edwin Fine wrote: -snip- > I was curious so I ran it on my configuration (Ubuntu 8.04 x86_64, > 2.4GHz Q6600, 8GB RAM, Erlang R12B-4). That configuration seems fairly similar - Ubuntu 8.04 x86_64, 2.4GHz Q6600, 4GB RAM, Erlang R12B-2 - but # *SMP without HiPE $ time /usr/local/src/otp_src_R12B-2/bin/erl -noshell -run chameneosredux main 6000000 real 18m31.693s user 35m41.518s sys 0m58.836s # *SMP disabled, without HiPE $ time /usr/local/src/otp_src_R12B-2/bin/erl -smp disable -noshell -run chameneosredux main 6000000 real 0m7.692s user 0m7.516s sys 0m0.100s From igouy2 Sat Oct 11 23:29:44 2008 From: igouy2 (Isaac Gouy) Date: Sat, 11 Oct 2008 14:29:44 -0700 (PDT) Subject: [erlang-questions] Chameneos.rednux micro benchmark Message-ID: <305780.85834.qm@web65410.mail.ac4.yahoo.com> If I compile for HiPE like this: /usr/local/bin/erlc +native +"{hipe, [o3]}" binarytrees.erl then trying to use -smp disable gives warnings like this: < =INFO REPORT==== 10-Oct-2008::17:33:14 === < Warning: not loading native code for module binarytrees: it was compiled for an incompatible runtime system; please regenerate native code for this runtime system Are there erlc command line options that would allow programs to be compiled for HiPE and run with -smp disable ? From tty.erlang Sun Oct 12 04:41:59 2008 From: tty.erlang (t ty) Date: Sat, 11 Oct 2008 22:41:59 -0400 Subject: [erlang-questions] Why is query a reserved word In-Reply-To: References: Message-ID: <290b3ba10810111941x234d54c0v1eda3fce665fb2e2@mail.gmail.com> It was a keyword for mnemosyne which has been superseded by QLC. If you are curious: http://web.mit.edu/erlang_vR11B-5/arch/sun4x_510/lib/erlang/lib/mnemosyne-1.2.7.1/doc/html/mnemosyne.html t On Sat, Oct 11, 2008 at 5:36 AM, Steve Davis wrote: > I notice that query is a reserved word in erlang - anyone know why? > It's the first/most obvious function name you'd choose when dealing > with a data store, so i'm interested in why it's reserved... > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From kenji.rikitake Sun Oct 12 07:44:44 2008 From: kenji.rikitake (Kenji Rikitake) Date: Sun, 12 Oct 2008 14:44:44 +0900 Subject: [erlang-questions] Chameneos.rednux micro benchmark In-Reply-To: <1688.88913.qm@web65409.mail.ac4.yahoo.com> References: <1688.88913.qm@web65409.mail.ac4.yahoo.com> Message-ID: <20081012054444.GA1517@k2r.org> Using the source code available at: http://shootout.alioth.debian.org/gp4/benchmark.php?test=chameneosredux&lang=hipe&id=1 FreeBSD 7.0-RELEASE i386 1.6GHz L2400 1.5GB RAM Erlang E12B-4 without HiPE compiled with stock gcc-4.2.1 % SMP enabled, without HiPE % time erl -smp enable -noshell -run chameneosredux main 6000000 199.488u 3.733s 1:42.93 197.4% 1833+689k 0+0io 0pf+0w % SMP disabled, without HiPE % time erl -smp disable -noshell -run chameneosredux main 6000000 36.405u 0.517s 0:37.02 99.7% 1690+826k 0+0io 0pf+0w FYI Kenji Rikitake From kenneth.lundin Sun Oct 12 09:27:26 2008 From: kenneth.lundin (Kenneth Lundin) Date: Sun, 12 Oct 2008 09:27:26 +0200 Subject: [erlang-questions] Fwd: Chameneos.rednux micro benchmark In-Reply-To: References: Message-ID: Hi, It is not at all surprising that the SMP version run much slower than the non SMP version. I looked at the program source and what I find there is an implementation that does not allow very much of parallell execution. The broker process is clearly a bottleneck since it is involved in everything. Every other process must wait for the broker process before it can continue it's execution. The other processes are also doing so little useful work so the task-switching and locking around the run-queue will become the dominating thing. When you have benchmarks with parallell processes that hardly perform any work and all processes are highly dependent on other processes, you can expect results like this, there is nothing wrong or bad with the ERlang SMP implementation because of that. It is the same with a SW project, do you think a 100 line program will be finished faster if you have 100 programmers instead of one? /Kenneth Erlang/OTP team, Ericsson 2008/10/11 Kevin Scaldeferri : > [sigh... hit Reply instead of Reply All] > > Begin forwarded message: > > From: Kevin Scaldeferri > Date: October 10, 2008 6:31:27 PM PDT > To: "Edwin Fine" > Subject: Re: [erlang-questions] Chameneos.rednux micro benchmark > > On Oct 10, 2008, at 4:19 PM, Edwin Fine wrote: > > It was run with HiPE. It's mentioned on the page that has the Erlang code. > > I was actually asking about when you ran it. I did know that the benchmark > site uses HiPE. > > A run of vmstat showed a minimum of about 15,000 context switches per second > and often more. Without the program running, there were only about 500 or so > per second. > ... > > I ran again with vmstat and -smp disabled. vmstat showed no noticable > difference in the cs column when the program was running compared to when it > was not: > > ... > > Tentative conclusion: this benchmark makes SMP Erlang do an excessive number > of context switches. Is that because it is jumping between cores, or because > of inter-process communication between cores? I can't answer that fully, but > I can see what happens if we retrict it to one core using one VM. > > This is not all that surprising. Consider the part of the benchmark where > there are 3 chameneos participating. Each of them, and the parent, will > likely end up on their own scheduler (on quad-core). They all send a > message then go to sleep. The parent receives the messages, processes some, > goes to sleep. Children wake up, get messages, send message, go to sleep. > Repeat. You can see that for much of the time, many of the schedules have > nothing to do, and their threads may be switched out. > Without SMP, all the Erlang processes run in the same scheduler thread, and > there is always work to be done, so no or few context switches. > Of course, for the portion with 10 chameneos, there is more often work that > can be done, but maybe still not enough to saturate all the cores all the > time. > > > So if it's not CPU-bound (60% idle), and it's not memory capacity bound > (virtual memory usage only 78MB), and it's not disk or network I/O bound, > what is it? > > a) as explained above, there are synchronization requirements as part of the > game that may make it difficult to saturate all the CPUs > b) I also speculated that migrating processes from one thread (core) to > another may be significant. I'm not really sure where to look in the OS > stats to find evidence to support this. (I guess you'd want to see if the > memory bus is saturated.) > > > I should also point out that it seems like there is either a significant > different between Erlang running on 2 and 4 cores, or between the chip > architectures themselves. Running parallel versions of other benchmarks on > my 2-core hardware, I usually find that the total CPU time used is only > slightly higher than a single-process version. However, on the Alioth > 4-core hardware, the total CPU usage is about double. (Look at the two > Erlang version for binary-trees and mandelbrot). I am inclined to think > Erlang is to blame, if only because the Haskell entries don't show the same > behavior. > > > -kevin > > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From qiulang Sun Oct 12 18:20:05 2008 From: qiulang (lang qiu) Date: Mon, 13 Oct 2008 00:20:05 +0800 Subject: [erlang-questions] confused by the grammar of split_binary/2 in the example of mp3_sync Message-ID: Hi, I am confused by the grammar of split_binary/2 in the example of mp3_sync in the book "Programming Erlang", get_word(N, Bin) -> * {_,<>} = split_binary(Bin, N), C.* I understand that *@spec split_binary(Bin, Pos)* -> {Bin1, Bin2} but how does the above clause work ? How does it make C get the first 4 bytes of Bin starting from N ? Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081013/65c2b8ad/attachment.html From kevin Sun Oct 12 18:25:46 2008 From: kevin (Kevin Scaldeferri) Date: Sun, 12 Oct 2008 09:25:46 -0700 Subject: [erlang-questions] Fwd: Chameneos.rednux micro benchmark In-Reply-To: References: Message-ID: <502F3A34-13DE-4DB7-AD5B-A8434416A97B@scaldeferri.com> On Oct 12, 2008, at 12:27 AM, Kenneth Lundin wrote: > Hi, > > It is not at all surprising that the SMP version run much slower than > the non SMP version. > I looked at the program source and what I find there is an > implementation that does not allow very much of > parallell execution. I agree with your analysis, but not with your conclusion. We can expect that the SMP version will not run much faster. However, we might also hope that it does not run orders of magnitude slower. At the moment, pthread based solutions are slaughtering Erlang, and also achieving up to 350% CPU utilization. -kevin From vychodil.hynek Sun Oct 12 18:55:20 2008 From: vychodil.hynek (Hynek Vychodil) Date: Sun, 12 Oct 2008 18:55:20 +0200 Subject: [erlang-questions] confused by the grammar of split_binary/2 in the example of mp3_sync In-Reply-To: References: Message-ID: <20081012165521.1DC7124012@relay.gooddata.com> 2008/10/12 lang qiu > Hi, > > I am confused by the grammar of split_binary/2 in the example of mp3_sync > in the book "Programming Erlang", > > get_word(N, Bin) -> > * {_,<>} = split_binary(Bin, N), C.* > > I understand that *@spec split_binary(Bin, Pos)* -> {Bin1, Bin2} but how > does the above clause work ? How does it make C get the first 4 bytes of Bin > starting from N ? > get_word(N, Bin) -> * {_,<>} = split_binary(Bin, N), C. *is shorthand for:* *get_word(N, Bin) -> * {Bin1, Bin2} = split_binary(Bin, N), **<> = Bin2,* * C.* Another way how to write it: get_word(N, Bin) -> *<<_:N/binary, C:4/binary,_/binary>> = Bin,* * C.* > > Thanks! > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -- --Hynek (Pichi) Vychodil -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081012/f81dd7c0/attachment.html From kevin Sun Oct 12 19:45:48 2008 From: kevin (Kevin Scaldeferri) Date: Sun, 12 Oct 2008 10:45:48 -0700 Subject: [erlang-questions] What erlc flags are needed to compile native (HiPE) to run on smp-disabled runtime? In-Reply-To: <6c2563b20810110921n28ff218p7707902cf0b29b5d@mail.gmail.com> References: <6c2563b20810110921n28ff218p7707902cf0b29b5d@mail.gmail.com> Message-ID: <9E2B06AB-1BBC-479A-B60F-ADF08FCAF94B@scaldeferri.com> On Oct 11, 2008, at 9:21 AM, Edwin Fine wrote: > To generate native code for smp-enabled runtime using erlc is easy. > I can't seem to make it happen for smp disabled runtime. > > If I start up Erlang with -smp disable and compile from within > Erlang, then it does what I want (creates a natively-compiled beam > for non-smp use). > > $ erl -smp disable > 1> c(mymodule, [native, {hipe, o3}]) > {ok,mymodule} > 8> > > But this is very inconvenient if a build system is created that > relies on erlc. Is there a better way? > I'm not on a HiPE enabled system, but supposedly hipe:help_options() will list the compile flags you can use. Maybe you'll find something there. -kevin PS: is there some secret HiPE documentation I've never managed to find? The "All you wanted to know" document is the best I've found, but I am sad to say it does not tell me everything I want to know :- (. (Also, producing HTML versions of the docs would be nice.) From mikpe Sun Oct 12 20:44:29 2008 From: mikpe (Mikael Pettersson) Date: Sun, 12 Oct 2008 20:44:29 +0200 Subject: [erlang-questions] What erlc flags are needed to compile native (HiPE) to run on smp-disabled runtime? In-Reply-To: <6c2563b20810110921n28ff218p7707902cf0b29b5d@mail.gmail.com> References: <6c2563b20810110921n28ff218p7707902cf0b29b5d@mail.gmail.com> Message-ID: <18674.17805.783465.813357@harpo.it.uu.se> Edwin Fine writes: > To generate native code for smp-enabled runtime using erlc is easy. I can't > seem to make it happen for smp disabled runtime. > > If I start up Erlang with -smp disable and compile from within Erlang, then > it does what I want (creates a natively-compiled beam for non-smp use). > > $ erl -smp disable > 1> c(mymodule, [native, {hipe, o3}]) > {ok,mymodule} > 8> > > But this is very inconvenient if a build system is created that relies on > erlc. Is there a better way? For various reasons the HiPE compiler can only generate code for the runtime system it's running on, so to generate non-SMP code you must run the compiler from within a non-SMP system. Unfortunately there doesn't seem to be any flag to erlc to make it choose a non-default runtime system, or a way to pass on raw options to erl instead of the compiler. erl (erlexec.c), however, can take command-line options from the environment, and the following seems to work: ERL_AFLAGS='-smp disable' erlc +native Module.erl But extending erts/etc/common/erlc.c to accept erlc -smp disable MoreOptions with the same meaning as for erl, or to accept erlc -erl ErlOption ... and pass ErlOption verbatim to erl would be a nicer solution. /Mikael From igouy2 Sun Oct 12 19:49:53 2008 From: igouy2 (Isaac Gouy) Date: Sun, 12 Oct 2008 10:49:53 -0700 (PDT) Subject: [erlang-questions] Fwd: Chameneos.rednux micro benchmark In-Reply-To: <502F3A34-13DE-4DB7-AD5B-A8434416A97B@scaldeferri.com> Message-ID: <543222.86452.qm@web65407.mail.ac4.yahoo.com> --- Kevin Scaldeferri wrote: > > On Oct 12, 2008, at 12:27 AM, Kenneth Lundin wrote: > > > Hi, > > > > It is not at all surprising that the SMP version run much slower > than > > the non SMP version. > > I looked at the program source and what I find there is an > > implementation that does not allow very much of > > parallell execution. > > I agree with your analysis, but not with your conclusion. > > We can expect that the SMP version will not run much faster. > However, we might also hope that it does not run orders of magnitude > slower. > > At the moment, pthread based solutions are slaughtering Erlang, and > also achieving up to 350% CPU utilization. Is there some well known understanding of how CPU utilization should be reported for multi-core and many-core? 350% utilization sounds quite wrong - but that's probably just me. From erlang-questions_efine Sun Oct 12 21:03:11 2008 From: erlang-questions_efine (Edwin Fine) Date: Sun, 12 Oct 2008 15:03:11 -0400 Subject: [erlang-questions] Fwd: Chameneos.rednux micro benchmark In-Reply-To: <543222.86452.qm@web65407.mail.ac4.yahoo.com> References: <502F3A34-13DE-4DB7-AD5B-A8434416A97B@scaldeferri.com> <543222.86452.qm@web65407.mail.ac4.yahoo.com> Message-ID: <6c2563b20810121203h5d6decd2sb80307a6f451b9bf@mail.gmail.com> 350% utilization means that 350/400 of the 4 cores are busy (i.e. 87.5% average CPU utilization). It's quite common to report CPU like that, at least in my experience. On Sun, Oct 12, 2008 at 1:49 PM, Isaac Gouy wrote: > > --- Kevin Scaldeferri wrote: > > > > > On Oct 12, 2008, at 12:27 AM, Kenneth Lundin wrote: > > > > > Hi, > > > > > > It is not at all surprising that the SMP version run much slower > > than > > > the non SMP version. > > > I looked at the program source and what I find there is an > > > implementation that does not allow very much of > > > parallell execution. > > > > I agree with your analysis, but not with your conclusion. > > > > We can expect that the SMP version will not run much faster. > > However, we might also hope that it does not run orders of magnitude > > slower. > > > > At the moment, pthread based solutions are slaughtering Erlang, and > > also achieving up to 350% CPU utilization. > > Is there some well known understanding of how CPU utilization should be > reported for multi-core and many-core? > > 350% utilization sounds quite wrong - but that's probably just me. > > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081012/708182a6/attachment.html From erlang-questions_efine Sun Oct 12 21:20:47 2008 From: erlang-questions_efine (Edwin Fine) Date: Sun, 12 Oct 2008 15:20:47 -0400 Subject: [erlang-questions] Further SMP and distributed performance comments Message-ID: <6c2563b20810121220v33244ee9we87d770555f42cf8@mail.gmail.com> Sorry, this email got sent before it was complete, so if you get it twice, my apologies. I never knew that, in Gmail, if you reply to an email while busy with another, it seems to send the one you were busy with first. I would have expected it to save to draft, but you live and learn. > > It is not at all surprising that the SMP version run much slower than > the non SMP version. > I looked at the program source and what I find there is an > implementation that does not allow very much of > parallell execution. > The broker process is clearly a bottleneck since it is involved in > everything. Every other process must wait for the broker process > before it can continue it's execution. Agreed. > > The other processes are also doing so little useful work so the > task-switching and locking around the run-queue will become the > dominating thing. I also thought so - but more about that later. When you have benchmarks with parallell processes that hardly perform > any work and all processes are highly dependent on > other processes, you can expect results like this, there is nothing > wrong or bad with the ERlang SMP implementation because of that. You are absolutely right that the benchmark is not representative of most real-world situations. It does, however, show up some weakness in the current Erlang SMP implementation. Other languages managed to run the same benchmark in a reasonable amount of time, therefore the benchmark itself cannot be totally invalid. Two orders of magnitude difference between running non-SMP and SMP is excessive under any circumstances. I tried some further experiments and got surprising results. I'd like to hear your opinion on this. I first hypothesized the following: 1. If the locking of the shared run queue is the problem, then if you run multiple VMs (nodes) each with a non-shared run queue (i.e. non-SMP) the program will run faster. 2. If the broker is the bottleneck, have multiple brokers and there should be a large improvement in performance. Initially, I modified the chameneos benchmark to allow more flexibility. - I changed it into a distributed system that allows you to choose how many separate Erlang nodes on which to run. The nodes have to be pre-started manually, unfortunately, but I haven't gotten around to trying to start them from within the program. - I increased the number of brokers to one broker per node. - I changed the benchmark code to spawn processes evenly across the number of nodes chosen. I also set it up that there will be an even number of "chameneos" processes per node, because one of the scenarios I wanted to test is if there is no cross-node communication - the broker on a given node only communicates with chameneos on the same node. This is to test how inter-node communications compares to intra-node communications. - The benchmark now has an extra step that gathered the intermediate results from all the brokers to present the final result. - I put lots of print statements in the code to show progress. - Finally, I removed the initial test that runs with only 3 chameneos because I only wanted to test the worst-case scenario (10 chameneos). The benchmark figures are therefore no longer directly comparable to the results on the alioth web site, but may be compared to each other only. The code I modified is now a bit of a mess because (a) I am not a highly experienced Erlang programmer and (b) I was rushing to try a whole lot of different things, so I was hacking it, but it does the intended job. I started four Erlang shells (nodes), all on the same 4-core Q6600 system. Initially I started the nodes with SMP enabled then I re-ran the tests with SMP disabled. I decided to test the following scenarios (parameters are [number of iterations, number of nodes]): 1. One Erlang SMP node, 1 broker, 10 chameneos - timer:tc(broker, start, [*6000000*, 1]) [353.18 secs]. 2. Four Erlang SMP nodes, 4 brokers, 10 chameneos - timer:tc(broker, start, [*6000000*, 4]). [12.42 secs] 3. One Erlang non-SMP node, 1 broker, 10 chameneos - timer:tc(broker, start, [*6000000*, 1]) [6.08 secs]. 4. Four Erlang non-SMP nodes, 4 brokers, 10 chameneos - timer:tc(broker, start, [*6000000*, 4]). [1.55 secs] Please note that the above results are for brokers that are constrained to be on the *same* node as the chameneos with which they are communicating. When this constraint is removed, that is, when brokers communicate with chameneos on different nodes, it is much slower, even in smp-disabled mode. To quantify that: Four Erlang non-SMP nodes, 4 brokers, 10 chameneos, *intra-node*communications - timer:tc(broker, start, [ *6000000*, 4]). *[1.55 secs]* Four Erlang non-SMP nodes, 4 brokers, 10 chameneos, *inter-node*communications - timer:tc(broker, start, [ *6000000*, 4]). *[192.6 secs]* Maybe this is to be expected, but if so, why? Should it be 124 times faster to communicate between Erlang nodes *on the same physical system* than it is to communicate within the nodes only? *Sample output of intra-node communication* Started broker <6364.44.0> on cwork_4 expecting 1500000 messages; collector pid = <0.39.0> Started broker <6363.44.0> on cwork_3 expecting 1500000 messages; collector pid = <0.39.0> Started broker <6362.44.0> on cwork_2 expecting 1500000 messages; collector pid = <0.39.0> Started broker <0.64.0> on cwork_1 expecting 1500000 messages; collector pid = <0.39.0> Started chameneos <0.65.0> for color blue on cwork_1 for broker <0.64.0> Started chameneos <0.66.0> for color red on cwork_1 for broker <0.64.0> Started chameneos <6362.45.0> for color yellow on cwork_2 for broker <6362.44.0> Started chameneos <6362.46.0> for color red on cwork_2 for broker <6362.44.0> Started chameneos <6363.45.0> for color yellow on cwork_3 for broker <6363.44.0> Started chameneos <6363.46.0> for color blue on cwork_3 for broker <6363.44.0> Started chameneos <6364.45.0> for color red on cwork_4 for broker <6364.44.0> Started chameneos <6364.46.0> for color yellow on cwork_4 for broker <6364.44.0> Started chameneos <0.67.0> for color red on cwork_1 for broker <0.64.0> Started chameneos <0.68.0> for color blue on cwork_1 for broker <0.64.0> *Sample output showing inter-node communication* Started broker <0.41.0> on cwork_1 expecting 1500000 messages; collector pid = <0.39.0> Started broker <6346.44.0> on cwork_2 expecting 1500000 messages; collector pid = <0.39.0> Started broker <6347.44.0> on cwork_3 expecting 1500000 messages; collector pid = <0.39.0> Started broker <6348.44.0> on cwork_4 expecting 1500000 messages; collector pid = <0.39.0> Started chameneos <0.53.0> for color blue on cwork_1 for broker <6348.44.0> Started chameneos <0.54.0> for color red on cwork_1 for broker <6348.44.0> Started chameneos <6346.45.0> for color yellow on cwork_2 for broker <6347.44.0> Started chameneos <6346.49.0> for color red on cwork_2 for broker <6347.44.0> Started chameneos <6347.45.0> for color yellow on cwork_3 for broker <6346.44.0> Started chameneos <6347.49.0> for color blue on cwork_3 for broker <6346.44.0> Started chameneos <6348.45.0> for color red on cwork_4 for broker <0.41.0> Started chameneos <6348.46.0> for color yellow on cwork_4 for broker <0.41.0> Started chameneos <0.55.0> for color red on cwork_1 for broker <6348.44.0> Started chameneos <0.56.0> for color blue on cwork_1 for broker <6348.44.0> Again, please excuse the ugly code. To compile, just erlc broker.erl and chameneos.erl. No HiPE used in these measurements. To run, start nodes with the sname cwork_1, cwork_2, ... e.g. $ erl +K true -sname cwork_1 -smp disable - OR - $ erl +K true -sname cwork_1 # to enable SMP Then in cwork_1, enter: > timer:tc(broker, start, [6000000,4]). The 4 is the number of nodes expected (cwork_1 .. cwork_4). Regards, Edwin Fine -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081012/9fa25e1e/attachment-0001.html -------------- next part -------------- A non-text attachment was scrubbed... Name: broker.erl Type: text/x-erlang Size: 6083 bytes Desc: not available Url : http://www.erlang.org/pipermail/erlang-questions/attachments/20081012/9fa25e1e/attachment-0002.bin -------------- next part -------------- A non-text attachment was scrubbed... Name: chameneos.erl Type: text/x-erlang Size: 2003 bytes Desc: not available Url : http://www.erlang.org/pipermail/erlang-questions/attachments/20081012/9fa25e1e/attachment-0003.bin From erlang-questions_efine Sun Oct 12 21:24:40 2008 From: erlang-questions_efine (Edwin Fine) Date: Sun, 12 Oct 2008 15:24:40 -0400 Subject: [erlang-questions] What erlc flags are needed to compile native (HiPE) to run on smp-disabled runtime? In-Reply-To: <9E2B06AB-1BBC-479A-B60F-ADF08FCAF94B@scaldeferri.com> References: <6c2563b20810110921n28ff218p7707902cf0b29b5d@mail.gmail.com> <9E2B06AB-1BBC-479A-B60F-ADF08FCAF94B@scaldeferri.com> Message-ID: <6c2563b20810121224h164d03f9pf382bb85f4e2d671@mail.gmail.com> I find myself in the same position as you do. Although it does a great job of compiling Erlang code, when it comes to acceptable levels of documentation, HiPE *is* unfortunately hype. I tried the hipe:help_options() but they don't give any clue about compiling in non-SMP mode. Apparently it cannot currently be using command-line flags (see Mikael Petterson's email). On Sun, Oct 12, 2008 at 1:45 PM, Kevin Scaldeferri wrote: > > On Oct 11, 2008, at 9:21 AM, Edwin Fine wrote: > > To generate native code for smp-enabled runtime using erlc is easy. I >> can't seem to make it happen for smp disabled runtime. >> >> If I start up Erlang with -smp disable and compile from within Erlang, >> then it does what I want (creates a natively-compiled beam for non-smp use). >> >> $ erl -smp disable >> 1> c(mymodule, [native, {hipe, o3}]) >> {ok,mymodule} >> 8> >> >> But this is very inconvenient if a build system is created that relies on >> erlc. Is there a better way? >> >> > I'm not on a HiPE enabled system, but supposedly hipe:help_options() will > list the compile flags you can use. Maybe you'll find something there. > > -kevin > > PS: is there some secret HiPE documentation I've never managed to find? > The "All you wanted to know" document is the best I've found, but I am sad > to say it does not tell me everything I want to know :-(. (Also, producing > HTML versions of the docs would be nice.) > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081012/b1bb461d/attachment.html From rvirding Sun Oct 12 22:15:59 2008 From: rvirding (Robert Virding) Date: Sun, 12 Oct 2008 22:15:59 +0200 Subject: [erlang-questions] jinterface In-Reply-To: <48ED8162.4050405@gmail.com> References: <6C2A5378-5BDE-4FF9-B2AF-790D1F78330B@kallisys.net> <48E7730B.3090506@gmail.com> <3dbc6d1c0810040711w26eae030pbcbccf7e1f4d5fd0@mail.gmail.com> <48E78277.4000809@gmail.com> <3dbc6d1c0810040757u795d521ex4223ad37a4ab3900@mail.gmail.com> <48ECA96B.2030201@gmail.com> <3dbc6d1c0810080657u4891111cr2052dc90488290f8@mail.gmail.com> <48ED8162.4050405@gmail.com> Message-ID: <3dbc6d1c0810121315rb049283mc3a5bf90296e2803@mail.gmail.com> 2008/10/9 Serge Aleynikov > Robert Virding wrote: > > - Modify your program so that you start a local group leader/io-server >> which >> does the formatting and just send the output iolists to the otp.netprocess. >> > > The otp.net node already has a mailbox for getting messages destined to > the io_server, and rpc requests carry the pid of that mailbox. Ideally I > wouldn't need to have another "proxy" io_server on the Erlang side that > would format and send requests to the connected otp.net hidden node. One reason I suggested this was for doing input. While for output you can modify io so that calling io_lib is done locally in the application process this does not work for input. For input the io-server has to be able to evaluate erlang functions, which I reckon can't be done in the otp.net node. Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081012/4109d440/attachment.html From rvirding Sun Oct 12 22:22:17 2008 From: rvirding (Robert Virding) Date: Sun, 12 Oct 2008 22:22:17 +0200 Subject: [erlang-questions] [enhancement] string:split/2 In-Reply-To: <20081010140950.GB3909@tsi.lv> References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> <34A27838-5CBA-425D-97A1-C2D2CF6F5456@cs.otago.ac.nz> <6c2563b20810082354u34372510n1fb4e1d23d777c23@mail.gmail.com> <781bce43-97e9-48fb-bba2-0ce230f2011a@t39g2000prh.googlegroups.com> <6c2563b20810090953n1b0c7672v17ceb84cbb59a1fd@mail.gmail.com> <20081010120401.GA3909@tsi.lv> <20081010140950.GB3909@tsi.lv> Message-ID: <3dbc6d1c0810121322s52919d8dl2feef72f61379c5b@mail.gmail.com> Can we end the language discussion? :-) I suggest a function string:split/2 which splits the input string with the separator and assumes that there is no separator and either end of the string. So: string:split("ab:de:fg", ":") ==> ["ab","de","fg"] string:split(":ab:de:fg:", ":") ==> [[],"ab","de","fg",[]] We call it split because it sounds better inspite of it being an unjoin. This also matches what will be in the re module (if they get it right) and what is in the old regexp module. And I don't really care what its relationship to join is called. :-) Robert 2008/10/10 Alex Chateau > > string:join/2 is not a surjective function, not a bijective one: > > Sorry, string:join/2 _is_ a surjective function > > -- > Alex Chateau > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081012/76f1ce53/attachment.html From erlang-questions_efine Sun Oct 12 22:24:52 2008 From: erlang-questions_efine (Edwin Fine) Date: Sun, 12 Oct 2008 16:24:52 -0400 Subject: [erlang-questions] What erlc flags are needed to compile native (HiPE) to run on smp-disabled runtime? In-Reply-To: <18674.17805.783465.813357@harpo.it.uu.se> References: <6c2563b20810110921n28ff218p7707902cf0b29b5d@mail.gmail.com> <18674.17805.783465.813357@harpo.it.uu.se> Message-ID: <6c2563b20810121324g5659d3bbj742b30e448c7fa3b@mail.gmail.com> Thanks, Mikael. On Sun, Oct 12, 2008 at 2:44 PM, Mikael Pettersson wrote: > Edwin Fine writes: > > To generate native code for smp-enabled runtime using erlc is easy. I > can't > > seem to make it happen for smp disabled runtime. > > > > If I start up Erlang with -smp disable and compile from within Erlang, > then > > it does what I want (creates a natively-compiled beam for non-smp use). > > > > $ erl -smp disable > > 1> c(mymodule, [native, {hipe, o3}]) > > {ok,mymodule} > > 8> > > > > But this is very inconvenient if a build system is created that relies > on > > erlc. Is there a better way? > > For various reasons the HiPE compiler can only generate code > for the runtime system it's running on, so to generate non-SMP > code you must run the compiler from within a non-SMP system. > > Unfortunately there doesn't seem to be any flag to erlc to make > it choose a non-default runtime system, or a way to pass on raw > options to erl instead of the compiler. erl (erlexec.c), however, > can take command-line options from the environment, and the > following seems to work: > > ERL_AFLAGS='-smp disable' erlc +native Module.erl > > But extending erts/etc/common/erlc.c to accept > > erlc -smp disable MoreOptions > > with the same meaning as for erl, or to accept > > erlc -erl ErlOption ... > > and pass ErlOption verbatim to erl would be a nicer solution. > > /Mikael > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081012/efdf3c5a/attachment.html From erlang-questions_efine Sun Oct 12 23:01:51 2008 From: erlang-questions_efine (Edwin Fine) Date: Sun, 12 Oct 2008 17:01:51 -0400 Subject: [erlang-questions] Notes about the modified chameneos/broker benchmark code I posted Message-ID: <6c2563b20810121401v45af985bkeaaf7d7e3854715f@mail.gmail.com> I forgot to add this in the original email. The code I sent to this list is based on the code posted to alioth for the benchmark game. I modified it heavily. The code as I modified it has a bug (or two): it expects there to be at least 2 chameneos (requester process) per broker. The reason for this is that (a) the code forces a broker to communicate only with chameneos running on the same node as the broker (unless you change the foldr to foldl as commented in the code) and (b) as in the original benchmark, the broker waits for pairs of messages, and will time out if there are fewer than 2 chameneos running on that node. The number of chameneos is currently hard-coded to 10 (by the colors list having 10 colors), so you can't have more than 5 nodes, otherwise there will be nodes that only have 1 chameneos per broker and the broker will time out. I am sure there are other bugs, given the hasty hacking, but I do believe that the code performs the algorithm from the benchmark correctly. If not, sorry, please let me know where I went wrong. Obviously if you parameterize it so that the chameneos to broker ratio is correct (>=2:1) then you can have as many nodes as you like. The way I wrote it to start up and distribute brokers and chameneos is probably very naive, and buggy, but I don't feel too bad about it because I was in a hurry and just trying to get something working to do some measurements, not write production-quality code. Nevertheless, I do apologize if this disgusts or annoys someone. If someone is kind enough to fix the bugs and "expertise" the code, I'd really like to see it the way it should be written. Regards Edwin Fine -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081012/86933036/attachment.html From jay Mon Oct 13 01:16:53 2008 From: jay (Jay Nelson) Date: Sun, 12 Oct 2008 16:16:53 -0700 Subject: [erlang-questions] Erlounge in Los Angeles, Wed Oct 15 Message-ID: <0ABE7E1D-9C63-49D0-9BB3-8F0291631A9D@duomark.com> Planning to meet Wednesday, Oct. 15 at 6:30pm. Chilbomyunok 3680 West 6th Street Los Angeles, CA 90020 (213) 387-9292 This is a Korean restaurant one block north of Wilshire, 2 blocks west of Normandie. Red line metro stop is at Wilshire and Normandie. I am expecting 6-8 people, more are welcome. jay From ok Mon Oct 13 04:28:47 2008 From: ok (Richard O'Keefe) Date: Mon, 13 Oct 2008 15:28:47 +1300 Subject: [erlang-questions] erlang-questions Digest, Vol 17, Issue 45 In-Reply-To: <6c2563b20810092224s1329d172s7ef39932018cdb51@mail.gmail.com> References: <8f24f4b10810091203i6eeb60f5q1b6bdaa483abea79@mail.gmail.com> <6c2563b20810091252l199969a3v2d82a5d9f87e0e91@mail.gmail.com> <8f24f4b10810091314r1586e999n999ffd972068e072@mail.gmail.com> <61EC12E1-6393-4427-846D-8B5DDC12B4D3@cs.otago.ac.nz> <6c2563b20810091911j581553d9s1f7bcc766620c48c@mail.gmail.com> <6c2563b20810092224s1329d172s7ef39932018cdb51@mail.gmail.com> Message-ID: <965113C8-AFE4-404A-9E07-4D703750108E@cs.otago.ac.nz> On 10 Oct 2008, at 6:24 pm, Edwin Fine wrote: > On Thu, Oct 9, 2008 at 11:53 PM, Richard O'Keefe > wrote: > On 10 Oct 2008, at 3:11 pm, Edwin Fine wrote: > Ok, then to preserve the Principle Of Least Astonishment, let > string:split accept a regular expression, which is just a string > with special RE operators. If the string contains no RE operators, > use an optimized special case of split (like the one you wrote) that > does not use an RE engine. Get the best of both worlds. > > No, that *violates* the principle of least astonishment, Big Time! > > First, absolutely nothing else whatever in the 'string' module > has anything to do with regular expressions. This would be > highly exceptional and very confusing. > > I disagree. Take for example the String classes of Ruby (http://www.ruby-doc.org/core/classes/String.html#M000818 > ), JavaScript (http://www.w3schools.com/jsref/jsref_split.asp) and > Java (http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#split(java.lang.String) > ), all of which use split with an RE. We *agree* that languages that have a 'split' function take a regular expression as an argument. If you will recall, that was my point. However, it is simply a fact that the 'string' module in >>>Erlang<<< has nothing connected with regular expressions in it. It used to, but they were removed. FOR ERLANG, it would now be astonishing to find just one function relating to regular expressions in 'string'. We *have* a split that uses a regular expression argument. It's in the regular expression module, where it is NOT surprising to find a regular expression used. You wanted a function that was a converse of the 'join' function. Since split-with-an-RE is *not* a converse of 'join', it cannot be the function you were asking for. A function of the kind you asked for *can* be written (and can be more efficient that regexp:split/2), and to be consistent with the Principle of Least Astonishment, it must not be given the name 'split', because a converse of the 'join' function does not do what the 'split' function does. > I think it's a matter of taste or opinion. I don't think split > belongs in the regexp module. It's about regular expressions. There is therefore no better place for it. Bear in mind that there is more than one syntax for regular expressions around. A posix_regexp:split/2 function and a pcre:split/2 function would behave differently, and it would be confusing to put them both in 'string'. > The new re module correctly does not include it. I think > regexp:split should be deprecated, in fact, the entire regexp module > should be deprecated because enough people have used it and been > burned by its lack of performance (because it is written in Erlang > when it should have been written in C) that it warrants an entire > Caveat section in the Erlang Efficiency Guide. Rewriting in C a regular expression module that works on *LINKED LISTS* of character codes would be like painting the Titanic. If you are that worried about bulk string handling, you are using binaries. We *AGREE* that regular expressions implemented at the level of C or better working on space-efficient strings would be a good thing. The lack of performance of the regexp module has very little to do with the language it is written in, by the way. On the contrary, it has to do with the *design*. There are two problems with regexp:split/2. (1) Presumably for the sake of 'convenience', the functions in the 'regexp' module that accept a regular expression accept EITHER a translated regular expression OR a string, which they first translate. It is fatally easy to write regexp:split(Line, "[ \t]*,[ \t]*") instead of {ok,Separator} = regexp:parse("[ \t]*,[ \t]*"), ... regexp:split(Line, Separator). I haven't measured how large the cost is, but it is certainly a trap for the unwary. (In AWK, the argument is usually translated at compile time.) (2) The internal representation is suboptimal. The regexp module translates regular expressions to trees, indeed, to ASTs. At match time, it interprets these trees. Grep and Mawk translate to a kind of automaton, which amongst other things admits a number of special case hacks. One thing that could be done fairly straightforwardly in a system like Erlang would be to have a HiPRE -- a run-time compiler from regexp ASTs to native code, which could be faster than a C implementation. By the way, the manual page for the 're' module starts out "This is an experimental module and the interface is subject to change" so to praise it for omitting 'split' is to go beyond what the evidence will bear. This is all the more so since the existing interface WILL do 90% of what split/2 needs: - compile a regular expression - find all the matches of that expression in a binary - report matches as location pairs To build split/2 on top of that, the hardest thing would be slogging your way through the 're.3' manual page figuring out the options. > Third, if there were a string:split/2 that used regular > expressions, that would make it very incompatible with > string:join/2, which doesn't. I thought we were wanting > string:join(string:split(String, Sep), Sep) > to give back Sep. > > Did you mean to write "to give back String?" Yes I did. > > > Yes, that is what we want, and it is what will happen, because it is > meaningless to join using an RE, isn't it. You can't join things > together with a regular expression. Exactly. Which is why 'split' is *NOT* a converse of 'join'. > So Sep would *have* to be a literal string. A literal string Sep passed to join/2 is treated as a string. A literal string Sep passed to split/2 is treated as a regular expression, which is NOT consistent with its use in join/2. > As it happens, split and join work exactly like this in other > languages and don't seem to overly confuse people. Well, in AWK it doesn't confuse people because AWK doesn't *have* a join/2 function. In Perl, the first argument of join/2 is normally written with quotation marks and the first argument of split/2 is normally written with slashes, acting as a visible reminder that it is not a string. But Erlang does not have the /.../ syntax for regular expressions. If you can find a language where strings and regular expressions have identical literal syntax and where people are not confused by split taking an RE and join taking a string, then you have a case. Only then. > So we are stuck with contriving some name because of history > (lists:split should have been lists:split_as from Haskell, regexp > already has split). > This, in spite of there being more than enough precedents amongst > other languages that use split as a method of their String classes. Since Erlang doesn't have classes, so what? It is you who I understand to be saying that "split" should have a regular expression argument because that's what other languages do. Fine. THAT'S WHAT WE HAVE IN ERLANG. We have a 'split' function that acts just like the split function in Perl (except for the argument order). If you want - a function called 'split' for splitting strings We agree about this! - that takes a regular expression argument We agree about this! - a function called 'join' that takes a string argument We agree about this! - a function X that is a converse of 'join' We agree about this! THEN the function X should not be called 'split'. It appears that we don't agree about this conclusion, and I honestly cannot see why not. Also, IF there were a unique best regular expression syntax we would agree that 'split' should be in the 'string' module. But there are several candidates on the table. Perl-compatible regular expressions are very expressive, but the expressiveness comes at a heavy price: efficiency. POSIX-compatible regular expressions are less expressive, but in return you get guaranteed linear time matching. I believe that the regular expression language in HyTime is comparable to POSIX ones. While I hold no brief for Perl-style "regular expressions", they are in wide use, so support is warranted. Support for efficiently implementable regular expressions is ALSO warranted, especially considering that there is a free C implementation that *is* efficient. So there is good reason to have at least two regular expression modules. (We agree that neither of them is the existing 'regexp'.) And that means there is good reason for each to have its own 'split' function. Let's drop the argument about whether the 'split' function > > By the way, I have a use for > string:join(reverse([Stuff|tail(reverse( > string:unjoin(Thing, ".")))]), ".") > so I would be very unhappy to have to write one of > those string literals as "\\." and the other NOT. > > That's a VERY good point. It's a glaring inconsistency. Other > languages deal with that by having a regular expression type and > special syntax (e.g. /abc/ or %r{abc}) to avoid confusion, and > (IIRC) if a string type is passed in stead of an RE type, the > receiving method treats it as a non-RE. Sadly, no. Take this example. my $data = 'a,b,c'; my @values = split(',', $data); print "$#values\n"; foreach my $item (@values) { print "$item\n"; } The output is 2 a b c Now change the commas to dots: my $data = 'a.b.c'; my @values = split('.', $data); # the rest as before The output is -1 The string has to be changed to '\\.' to work as expected. (Tested with Perl 5.8.8, tested on UltraSPARC II Solaris 2.10 and Intel Core 2 Duo MacOS 10.5.4.) I have no idea what other languages do, except for Squeak Smalltalk, whose analogue of 'split' takes only a fun as an argument. > One would then be able to use the same literal in both join and > unjoin. Maybe Erlang should have a new regular expression type and > syntax, seeing as it is going to be used in more and more > applications that do heavy text processing. We've had that debate before. The position I took then was that text patterns in a language like Erlang should be expressed as trees, rather like Bigloo. See http://www-sop.inria.fr/mimosa/fp/Bigloo/doc/bigloo-12.html#Regular-parsing This is vastly more convenient for programs that *construct* regular expressions than the traditional AWK-style // stuff, and for tricky regular expressions, it has been my experience that it is easier to get right than the linear form. > The fact that for example "add" and "subtract" are not related > in that way really doesn't signify anything, just as the fact > that there are many colours doesn't mean that black is a bad > choice. > > But you wouldn't create a function named "unadd" when "subtract " is > a more acceptable usage - would you? If there was *already* an *incompatible* function called 'subtract', I might be driven to it. Come to think of it, in Smalltalk the opposite of 'add' is 'remove', not 'subtract'. > Interesting. One of the words you wrote above gave me an idea. How > about meeting halfway? How about two new functions, > string:separate(String, Separator) and string:unseparate(List, > Separator)? No clash and it makes even more sense (to me) than split > and join. Suits me. 'join' already has other meanings in computing, like |><|. From ok Mon Oct 13 04:48:15 2008 From: ok (Richard O'Keefe) Date: Mon, 13 Oct 2008 15:48:15 +1300 Subject: [erlang-questions] Types and specs [WAS: [enhancement] string:split/2] In-Reply-To: <48EF3D78.2060306@cs.ntua.gr> References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> <48EF3D78.2060306@cs.ntua.gr> Message-ID: <795E68D8-738A-4EE5-88E4-0F607132026C@cs.otago.ac.nz> On 11 Oct 2008, at 12:33 am, Kostis Sagonas wrote that [[char(),...]] means list of non-empty strings, which is more precise than [string()]. Would [char()|string()] also work? > > On the other hand, I can see how this may look a bit strange to some > and have for a long time now pondered whether a non_empty_string() > type alias might be added to the list of built-in types. It would certainly make some types easier to read. From ok Mon Oct 13 06:00:38 2008 From: ok (Richard O'Keefe) Date: Mon, 13 Oct 2008 17:00:38 +1300 Subject: [erlang-questions] [enhancement] string:split/2 In-Reply-To: <3dbc6d1c0810121322s52919d8dl2feef72f61379c5b@mail.gmail.com> References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> <34A27838-5CBA-425D-97A1-C2D2CF6F5456@cs.otago.ac.nz> <6c2563b20810082354u34372510n1fb4e1d23d777c23@mail.gmail.com> <781bce43-97e9-48fb-bba2-0ce230f2011a@t39g2000prh.googlegroups.com> <6c2563b20810090953n1b0c7672v17ceb84cbb59a1fd@mail.gmail.com> <20081010120401.GA3909@tsi.lv> <20081010140950.GB3909@tsi.lv> <3dbc6d1c0810121322s52919d8dl2feef72f61379c5b@mail.gmail.com> Message-ID: <3053526A-C808-4A9D-93CD-E9C2B3511B43@cs.otago.ac.nz> On 13 Oct 2008, at 9:22 am, Robert Virding wrote: > Can we end the language discussion? :-) > > I suggest a function string:split/2 which splits the input string > with the separator and assumes that there is no separator and either > end of the string. So: > > string:split("ab:de:fg", ":") ==> ["ab","de","fg"] > string:split(":ab:de:fg:", ":") ==> [[],"ab","de","fg",[]] This violates the assumption "that there is no separator [at] either end of the string". To make that assumption is to assume that something that _looks_ like a separator at either end _isn't_ one, so string:split(":ab:de:fg:", ":") ==> [":ab","de","fg:"] under that assumption. I _think_ you are talking about the issue that came up last week with *multicharacter* separators: string:split("a:::b", "::") ==> ["a:","b"] or ["a",":b"] -- the code I posted does this As I recall it, we don't have a resolution for that. The posted 'unjoin' takes the _leftmost_ occurrence of a multicharacter separator as a separator, but it could just as well take the _rightmost_. (Existence proof: reverse . map reverse . (\ s -> unjoin s sep) . reverse) > We call it split because it sounds better inspite of it being an > unjoin. s/inspite of/in spite of/ or more idiomatically, s/inspite of/despite/ > This also matches what will be in the re module (if they get it > right) and what is in the old regexp module. No, it DOESN'T match it. It CONFLICTS with regexp splitting. In fact, that's why it is useful! Call it disjoin/2 if you will (that being an existing English word). But please do not give it the same name as an existing function with significantly incompatible behaviour. > From igouy2 Mon Oct 13 07:18:26 2008 From: igouy2 (Isaac Gouy) Date: Sun, 12 Oct 2008 22:18:26 -0700 (PDT) Subject: [erlang-questions] What erlc flags are needed to compile native (HiPE) to run on smp-disabled runtime? In-Reply-To: <6c2563b20810121324g5659d3bbj742b30e448c7fa3b@mail.gmail.com> Message-ID: <750844.82679.qm@web65408.mail.ac4.yahoo.com> > On Sun, Oct 12, 2008 at 2:44 PM, Mikael Pettersson > > For various reasons the HiPE compiler can only generate code > > for the runtime system it's running on, so to generate non-SMP > > code you must run the compiler from within a non-SMP system. I've now made a separate build using --disable-smp-support so both HiPE and -smp disable can be used: http://shootout.alioth.debian.org/u32/erlang.php http://shootout.alioth.debian.org/u64/erlang.php From kostis Mon Oct 13 08:49:11 2008 From: kostis (Kostis Sagonas) Date: Mon, 13 Oct 2008 09:49:11 +0300 Subject: [erlang-questions] Types and specs [WAS: [enhancement] string:split/2] In-Reply-To: <795E68D8-738A-4EE5-88E4-0F607132026C@cs.otago.ac.nz> References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> <48EF3D78.2060306@cs.ntua.gr> <795E68D8-738A-4EE5-88E4-0F607132026C@cs.otago.ac.nz> Message-ID: <48F2EF67.7010005@cs.ntua.gr> Richard O'Keefe wrote: > > On 11 Oct 2008, at 12:33 am, Kostis Sagonas wrote that > [[char(),...]] means list of non-empty strings, which > is more precise than [string()]. > > Would [char()|string()] also work? No. This is a different type, which does not express what you want here. Note that in the language of types | does not mean list tail, but instead means type union. The above type denotes a (possibly empty) list consisting of characters or strings. Quite different from [[char(),...]]. Kostis From ulf.wiger Mon Oct 13 09:20:19 2008 From: ulf.wiger (Ulf Wiger (TN/EAB)) Date: Mon, 13 Oct 2008 09:20:19 +0200 Subject: [erlang-questions] Lots of questions about error_logger In-Reply-To: <3bff71aa0810100809w1b5282dfhd7bd06876f255605@mail.gmail.com> References: <3bff71aa0810100809w1b5282dfhd7bd06876f255605@mail.gmail.com> Message-ID: <48F2F6B3.70203@ericsson.com> Sergey A. skrev: > Hello. > > In the first place, sorry for several different questions placed in > one letter. I know it's something wearily to answer a list of > questions. > > I tried using error_logger as a tool for handling error reports and > I've came across some oddities: > > #1. Is there a way to set SASL options (I'm about sasl_error_logger, > errlog_type etc) from the Erlang code at runtime without using a > .config file + the "-config" argument? I just want to give an end user > only one config file to edit and use values from that to setup SASL. I guess application:set_env(App, Par, Val) is what you're after? However, the function comes with a big fat warning: "Use this function only if you know what you are doing, that is, on your own applications. It is very application and configuration parameter dependent when and how often the value is read by the application, and careless use of this function may put the application in a weird, inconsistent, and malfunctioning state." (http://www.erlang.org/doc/apps/kernel/application.html) Especially with things like the error logger, the value is expected to be present from the beginning, and the warning is particularly relevant. If you don't want to mess with a config file, you can add the parameters to the command line, using -App Par Val constructs. Remember to escape special characters and omit spaces if you want to declare complex terms this way. It's easy with simple values, like erl -sasl error_logger_mf_maxbytes 100000 BR, Ulf W From vladdu55 Mon Oct 13 09:22:50 2008 From: vladdu55 (Vlad Dumitrescu) Date: Mon, 13 Oct 2008 09:22:50 +0200 Subject: [erlang-questions] Fwd: [enhancement] string:split/2 In-Reply-To: References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> <6c2563b20810082343j255330ccp396cf4f8da0d2fe4@mail.gmail.com> <330AAA17-394B-44D0-9E09-7CEE4B6BF9C9@cs.otago.ac.nz> <6c2563b20810091932x245481ew538675b5526e8db3@mail.gmail.com> <8689C36E-B021-4300-88E1-AB66164891F6@cs.otago.ac.nz> <95be1d3b0810092356lc2f1d93m5e86a0ecc97358cd@mail.gmail.com> Message-ID: <95be1d3b0810130022h6de0a4ffne24e606310086053@mail.gmail.com> I believe Richard's question wasn't aimed at just me, so I'm forwarding it here. /Vlad ---------- Forwarded message ---------- From: Richard O'Keefe Date: Mon, Oct 13, 2008 at 04:41 Subject: Re: [erlang-questions] [enhancement] string:split/2 On 10 Oct 2008, at 7:56 pm, Vlad Dumitrescu wrote: > > On Fri, Oct 10, 2008 at 07:00, Richard O'Keefe wrote: >> >> Talking about "not requir[ing] HiPE" is like saying >> "I demand that your C compiler produce efficient code >> without optimisation." > > A side issue: the above comparison is not really correct. Until HiPE > is available on all platforms and architectures supported by Erlang, > it is perfectly valid to not want to have it as a requirement for an > application. The thing we are all agreed on is that it is desirable to have HiPE "on all platforms and architectures supported by Erlang". I was willing to pay USD 160 for a licence to the Intel C compiler on my Mac. All things considered, I'd be happy to donate a similar amount towards getting HiPE going. Could there be a HiPE foundation? From rvirding Mon Oct 13 12:14:04 2008 From: rvirding (Robert Virding) Date: Mon, 13 Oct 2008 12:14:04 +0200 Subject: [erlang-questions] [enhancement] string:split/2 In-Reply-To: <3053526A-C808-4A9D-93CD-E9C2B3511B43@cs.otago.ac.nz> References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> <34A27838-5CBA-425D-97A1-C2D2CF6F5456@cs.otago.ac.nz> <6c2563b20810082354u34372510n1fb4e1d23d777c23@mail.gmail.com> <781bce43-97e9-48fb-bba2-0ce230f2011a@t39g2000prh.googlegroups.com> <6c2563b20810090953n1b0c7672v17ceb84cbb59a1fd@mail.gmail.com> <20081010120401.GA3909@tsi.lv> <20081010140950.GB3909@tsi.lv> <3dbc6d1c0810121322s52919d8dl2feef72f61379c5b@mail.gmail.com> <3053526A-C808-4A9D-93CD-E9C2B3511B43@cs.otago.ac.nz> Message-ID: <3dbc6d1c0810130314x630f4736q90162ed739321ac0@mail.gmail.com> 2008/10/13 Richard O'Keefe > > On 13 Oct 2008, at 9:22 am, Robert Virding wrote: > > I suggest a function string:split/2 which splits the input string with the >> separator and assumes that there is no separator and either end of the >> string. So: >> >> string:split("ab:de:fg", ":") ==> ["ab","de","fg"] >> string:split(":ab:de:fg:", ":") ==> [[],"ab","de","fg",[]] >> > > This violates the assumption "that there is no separator [at] > either end of the string". To make that assumption is to > assume that something that _looks_ like a separator at either > end _isn't_ one, so > string:split(":ab:de:fg:", ":") ==> [":ab","de","fg:"] > under that assumption. > > I _think_ you are talking about the issue that came up > last week with *multicharacter* separators: > string:split("a:::b", "::") > ==> ["a:","b"] > or ["a",":b"] -- the code I posted does this That was me being extremely unclear. The examples I showed describe what I mean, and not what I wrote. I think the function should search for the separator from left-to-right as your second example. The question is how do you describe in text what it returns when it finds the separator at the beginning and at the end. This also matches what will be in the re module (if they get it right) and >> what is in the old regexp module. >> > > No, it DOESN'T match it. It CONFLICTS with regexp splitting. > In fact, that's why it is useful! regexp:split("ab:cd:ef", ":"). ==> {ok,["ab","cd","ef"]} regexp:split(":ab:cd:ef:", ":"). ==> {ok,[[],"ab","cd","ef",[]]} regexp:split(":::ab:::cd::ef", "::"). ==> {ok,[[],":ab",":cd","ef"]} Or have I misunderstood you. What the new re:split will do I don't know, hopefully the same thing. Not to be different I have also included some code for a split/2. It is a bit simpler than yours, at least I think so, but no guarantees for speed. Although it would be easy to modify so that strip_sep/2 never returns but directly calls strip/4. %% strip(String, Separator) -> [String]. strip(S, Sep) -> strip(S, Sep, [], []). strip([H|T]=S0, Sep, R, Rs) -> case strip_sep(S0, Sep) of {yes,S1} -> strip(S1, Sep, [], [R|Rs]); no -> strip(T, Sep, [H|R], Rs) end; strip([], _, R, Rs) -> strip_rev([R|Rs], []). strip_rev([R|Rs], Acc) -> strip_rev(Rs, [reverse(R)|Acc]); strip_rev([], Acc) -> Acc. strip_sep([C|S], [C|Sep]) -> strip_sep(S, Sep); strip_sep(S, []) -> {yes,S}; strip_sep(_, _) -> no. Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081013/45892c5e/attachment.html From bgustavsson Mon Oct 13 12:25:17 2008 From: bgustavsson (Bjorn Gustavsson) Date: Mon, 13 Oct 2008 12:25:17 +0200 Subject: [erlang-questions] [erlang-patches] code_server & ERL_LIBS bug In-Reply-To: <48EF60D1.1030704@gmail.com> References: <48EF60D1.1030704@gmail.com> Message-ID: <6672d0160810130325h2cf5a74cr7e9536a1453d86ec@mail.gmail.com> 2008/10/10 Serge Aleynikov > There's an error in code server that causes erl & erlc to hang at startup > if ERL_LIBS environment variable is set to an empty string or a string > containing non-existing directories. > > Thanks! It will be corrected in R12B-5. /Bjorn -- Bj?rn Gustavsson, Erlang/OTP, Ericsson AB -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081013/8acdc51e/attachment.html From rvg Mon Oct 13 14:14:41 2008 From: rvg (Rudolph van Graan) Date: Mon, 13 Oct 2008 14:14:41 +0200 Subject: [erlang-questions] Are there any companies that hire Erlangers? In-Reply-To: <290b3ba10810100410k205642demb8ec48b7f361a3e4@mail.gmail.com> References: <2a67d3ff0810091808x2c4be63dpbe1ef8f79654593c@mail.gmail.com> <6c2563b20810091937u2b411cean65d972caa4d60bd9@mail.gmail.com> <290b3ba10810100410k205642demb8ec48b7f361a3e4@mail.gmail.com> Message-ID: <8BC540AA-B6B7-4EBC-A3DB-D41AF6E259C5@patternmatched.com> Hi All, Pattern Matched Technologies (www.patternmatched.com) is looking for programmers right now. We work closely with Francesco and ETC (Erlang Training and Consulting). We are based in South Africa and have a number of positions available. All our products are Erlang-based - we have been working with the language for about 8 years now. Please do not hesitate to contact me if you are interested. Rudolph Pattern Matched Technologies E-Mail: rvg Tel: 086 1000 700 (SA Only) Mobile: +27 83 390 7767 Fax: +27 12 665 9566 Web: www.patternmatched.com On Oct 10, 2008, at 1:10 PM, t ty wrote: > Hello All, > > I have yet to find a company that programs using Erlang, and I'd > really > like to work for one. Am I looking in the wrong place, do any of you > know a > company that uses Erlang as the main language? > > -Gene From klsr.2008 Mon Oct 13 14:11:41 2008 From: klsr.2008 (Klsr K) Date: Mon, 13 Oct 2008 12:41:41 +0030 Subject: [erlang-questions] Erlang linked in driver question Message-ID: <4ae243650810130511y17ed29e7pdf8534af05157574@mail.gmail.com> Hi to all i was going through the linked in driver program . . . In gen_tcp for gen_tcp:connect for each connection they opening new port and my question is there is any diff when we open the port for each connect and opening the port when loading the driver and using that port for communication for all connection and send.... From chandrashekhar.mullaparthi Mon Oct 13 16:41:59 2008 From: chandrashekhar.mullaparthi (Chandru) Date: Mon, 13 Oct 2008 15:41:59 +0100 Subject: [erlang-questions] Are there any companies that hire Erlangers? In-Reply-To: <6c2563b20810091937u2b411cean65d972caa4d60bd9@mail.gmail.com> References: <2a67d3ff0810091808x2c4be63dpbe1ef8f79654593c@mail.gmail.com> <6c2563b20810091937u2b411cean65d972caa4d60bd9@mail.gmail.com> Message-ID: T-Mobile UK uses Erlang/OTP a lot. There is currently a vacant contracting position if anyone is interested. cheers Chandru 2008/10/10 Edwin Fine > Not to be funny, but in which country? I mean, where are you looking? In > the U.K for example, I think I know of a company or two that uses primarily > Erlang (Erlang Training and Consulting is one, and I think LShift is another > - http://www.lshift.net/recruitment). > > 2008/10/9 G.S. > >> Hello All, >> >> I have yet to find a company that programs using Erlang, and I'd really >> like to work for one. Am I looking in the wrong place, do any of you know a >> company that uses Erlang as the main language? >> >> -Gene >> >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions >> http://www.erlang.org/mailman/listinfo/erlang-questions >> > > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081013/7dab2975/attachment.html From kevin Mon Oct 13 18:13:43 2008 From: kevin (Kevin Scaldeferri) Date: Mon, 13 Oct 2008 09:13:43 -0700 Subject: [erlang-questions] What erlc flags are needed to compile native (HiPE) to run on smp-disabled runtime? In-Reply-To: <750844.82679.qm@web65408.mail.ac4.yahoo.com> References: <750844.82679.qm@web65408.mail.ac4.yahoo.com> Message-ID: <44F7E98A-6B45-4983-9E06-76AFF0C05CFC@scaldeferri.com> On Oct 12, 2008, at 10:18 PM, Isaac Gouy wrote: >> On Sun, Oct 12, 2008 at 2:44 PM, Mikael Pettersson > >>> For various reasons the HiPE compiler can only generate code >>> for the runtime system it's running on, so to generate non-SMP >>> code you must run the compiler from within a non-SMP system. > > I've now made a separate build using --disable-smp-support so both > HiPE > and -smp disable can be used: > > http://shootout.alioth.debian.org/u32/erlang.php > > http://shootout.alioth.debian.org/u64/erlang.php > This is all well and good for chameneos, but it looks like all erlang entries are being run this way now, including ones like the binary- trees entries that was written to take advantage of multiple cores and which does go faster with SMP: http://shootout.alioth.debian.org/u64/benchmark.php?test=binarytrees&lang=hipe&id=2 -kevin From igouy2 Mon Oct 13 19:00:08 2008 From: igouy2 (Isaac Gouy) Date: Mon, 13 Oct 2008 10:00:08 -0700 (PDT) Subject: [erlang-questions] What erlc flags are needed to compile native (HiPE) to run on smp-disabled runtime? In-Reply-To: <44F7E98A-6B45-4983-9E06-76AFF0C05CFC@scaldeferri.com> Message-ID: <529648.50104.qm@web65404.mail.ac4.yahoo.com> --- Kevin Scaldeferri wrote: > > On Oct 12, 2008, at 10:18 PM, Isaac Gouy wrote: > > >> On Sun, Oct 12, 2008 at 2:44 PM, Mikael Pettersson > > > > >>> For various reasons the HiPE compiler can only generate code > >>> for the runtime system it's running on, so to generate non-SMP > >>> code you must run the compiler from within a non-SMP system. > > > > I've now made a separate build using --disable-smp-support so both > > > HiPE > > and -smp disable can be used: > > > > http://shootout.alioth.debian.org/u32/erlang.php > > > > http://shootout.alioth.debian.org/u64/erlang.php > > > > > This is all well and good for chameneos, but it looks like all erlang > entries are being run this way now, including ones like the binary- > trees entries that was written to take advantage of multiple cores > and which does go faster with SMP There are 4 sets of measurements. Those 2 sets of measurements show programs forced to use a single core. These 2 sets of measurements show programs allowed to use multiple cores, and use -smp enable http://shootout.alioth.debian.org/u32q/erlang.php http://shootout.alioth.debian.org/u64q/erlang.php From kenneth.lundin Mon Oct 13 20:00:50 2008 From: kenneth.lundin (Kenneth Lundin) Date: Mon, 13 Oct 2008 20:00:50 +0200 Subject: [erlang-questions] Fwd: Chameneos.rednux micro benchmark In-Reply-To: <502F3A34-13DE-4DB7-AD5B-A8434416A97B@scaldeferri.com> References: <502F3A34-13DE-4DB7-AD5B-A8434416A97B@scaldeferri.com> Message-ID: Hi, We have now looked a bit closer on why this benchmark does perform so bad with Erlang SMP. There are 2 major things that stand out: 1) The locking of the single run-queue between the pthread based schedulers is the main thing. There is an enormous amount of locking and lock-conflicts here. 2) One single process (the broker) to which all others are sending messages does also cause a lot of locking (the message-queue and heap on the receiving process requires a lock before the sending process can complete it's send operation) Fortunately we have ongoing work with optimizations in these areas which will have major impact on this benchmark. On Sun, Oct 12, 2008 at 6:25 PM, Kevin Scaldeferri wrote: > > On Oct 12, 2008, at 12:27 AM, Kenneth Lundin wrote: > >> Hi, >> >> It is not at all surprising that the SMP version run much slower than >> the non SMP version. >> I looked at the program source and what I find there is an >> implementation that does not allow very much of >> parallel execution. > > I agree with your analysis, but not with your conclusion. > > We can expect that the SMP version will not run much faster. However, we > might also hope that it does not run orders of magnitude slower. > > At the moment, pthread based solutions are slaughtering Erlang, and also > achieving up to 350% CPU utilization. A pthread based solution written in C for this particular problem is not a fair comparison since the Erlang VM is designed to support general execution of thousands of processes on top of a number of pthreads based schedulers. The VM has to handle all Erlang programs whatever execution pattern they have. There is an overhead for being able to execute Erlang processes and IO in a soft real time way. Normally this overhead is around 20% compared with the non SMP VM. With this particular benchmark each process perform so little execution each time it is run and the number of simultaneously runnable processes goes like a Jojo between first 1 to 4 and later 1-12. The effect of this is that it costs more to schedule in a process than it costs to run it's code. Most probably the benchmark can be written in a more efficient way for the Erlang VM as well. Maybe I will take the time to do that later. /Kenneth Erlang/OTP team, Ericsson > > -kevin > From mickael.remond Mon Oct 13 19:35:57 2008 From: mickael.remond (=?UTF-8?Q?Micka=C3=ABl_R=C3=A9mond?=) Date: Mon, 13 Oct 2008 19:35:57 +0200 Subject: [erlang-questions] Erlounge in Los Angeles, Wed Oct 15 In-Reply-To: <0ABE7E1D-9C63-49D0-9BB3-8F0291631A9D@duomark.com> References: <0ABE7E1D-9C63-49D0-9BB3-8F0291631A9D@duomark.com> Message-ID: Hello Jay, Too bad, I will miss it from a few days. I would love to meet Erlanger and XMPP fan in Los Angeles on sunday 19th Oct or on the 22th Oct. I am arriving on Saturday (18th Oct) and living an thursday (23rd Oct). Le 13 oct. 08 ? 01:16, Jay Nelson a ?crit : > Planning to meet Wednesday, Oct. 15 at 6:30pm. > > Chilbomyunok > 3680 West 6th Street > Los Angeles, CA 90020 > (213) 387-9292 > > This is a Korean restaurant one block north of Wilshire, > 2 blocks west of Normandie. Red line metro stop is > at Wilshire and Normandie. > > I am expecting 6-8 people, more are welcome. > > jay > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -- Micka?l R?mond http://www.process-one.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081013/3a172726/attachment.html From josh Mon Oct 13 20:02:01 2008 From: josh (Josh Goldberg) Date: Mon, 13 Oct 2008 11:02:01 -0700 Subject: [erlang-questions] [spam?] Are there any companies that hire Erlangers? In-Reply-To: <2a67d3ff0810091808x2c4be63dpbe1ef8f79654593c@mail.gmail.com> References: <2a67d3ff0810091808x2c4be63dpbe1ef8f79654593c@mail.gmail.com> Message-ID: <4c7f9e8d0810131102q83cfeb4tfaefb285e0a751d6@mail.gmail.com> I've gotten a couple job inquiries from linkedin.com with erlang in my profile. 2008/10/9 G.S. > Hello All, > > I have yet to find a company that programs using Erlang, and I'd really > like to work for one. Am I looking in the wrong place, do any of you know a > company that uses Erlang as the main language? > > -Gene > > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081013/a7683be3/attachment.html From david.koch Mon Oct 13 15:04:07 2008 From: david.koch (=?iso-8859-1?Q?david.koch?=) Date: Mon, 13 Oct 2008 15:04:07 +0200 Subject: [erlang-questions] =?iso-8859-1?q?REF=3A_ErlIDE_0=2E3=2E94_on_Ecl?= =?iso-8859-1?q?ipse_3=2E4=2E1_M20080911-1700?= Message-ID: The Erlang perspective just doesn't show anymore... Am I mistaken with my upgrade ? Any solution ? Sorry to be a pain in the a.. ! Kochise ---------------------- ALICE N?1 de la RELATION CLIENT 2008*-------------------- D?couvrez vite l'offre exclusive ALICE BOX! En cliquant ici http://abonnement.aliceadsl.fr Offre soumise ? conditions.*Source : TNS SOFRES / BEARING POINT. Secteur Fournisseur d.Acc?s Internet From vladdu55 Mon Oct 13 20:20:37 2008 From: vladdu55 (Vlad Dumitrescu) Date: Mon, 13 Oct 2008 20:20:37 +0200 Subject: [erlang-questions] REF: ErlIDE 0.3.94 on Eclipse 3.4.1 M20080911-1700 In-Reply-To: References: Message-ID: <95be1d3b0810131120x1de27bfewfe6c275d4daf0b13@mail.gmail.com> On Mon, Oct 13, 2008 at 15:04, david.koch wrote: > The Erlang perspective just doesn't show anymore... Am I mistaken > with my upgrade ? Any solution ? Sorry to be a pain in the a.. ! Hi, Please send me some more details about your settings and I will help you. >From which version did you update? regards, Vlad From kevin Mon Oct 13 20:33:30 2008 From: kevin (Kevin Scaldeferri) Date: Mon, 13 Oct 2008 11:33:30 -0700 Subject: [erlang-questions] What erlc flags are needed to compile native (HiPE) to run on smp-disabled runtime? In-Reply-To: <529648.50104.qm@web65404.mail.ac4.yahoo.com> References: <529648.50104.qm@web65404.mail.ac4.yahoo.com> Message-ID: <367ACD9E-0875-4A2F-989A-9331AF4F39CC@scaldeferri.com> On Oct 13, 2008, at 10:00 AM, Isaac Gouy wrote: > > --- Kevin Scaldeferri wrote: > >> >> On Oct 12, 2008, at 10:18 PM, Isaac Gouy wrote: >> >>>> On Sun, Oct 12, 2008 at 2:44 PM, Mikael Pettersson >> >>> >>>>> For various reasons the HiPE compiler can only generate code >>>>> for the runtime system it's running on, so to generate non-SMP >>>>> code you must run the compiler from within a non-SMP system. >>> >>> I've now made a separate build using --disable-smp-support so both >> >>> HiPE >>> and -smp disable can be used: >>> >>> http://shootout.alioth.debian.org/u32/erlang.php >>> >>> http://shootout.alioth.debian.org/u64/erlang.php >>> >> >> >> This is all well and good for chameneos, but it looks like all erlang >> entries are being run this way now, including ones like the binary- >> trees entries that was written to take advantage of multiple cores >> and which does go faster with SMP > > There are 4 sets of measurements. > > Those 2 sets of measurements show programs forced to use a single > core. > > These 2 sets of measurements show programs allowed to use multiple > cores, and use -smp enable > > http://shootout.alioth.debian.org/u32q/erlang.php > > http://shootout.alioth.debian.org/u64q/erlang.php > Ahh, my mistake. I didn't look closely enough at the headers. -kevin From dloutrein.lists Mon Oct 13 23:47:40 2008 From: dloutrein.lists (denis) Date: Mon, 13 Oct 2008 17:47:40 -0400 Subject: [erlang-questions] core erlang, scope, primop Message-ID: <349ebab60810131447x2391571ei4c01e5d4e6f5c091@mail.gmail.com> Hi all, I've two questions on core erlang: Concerning the scope of variables: when using let, the scope of the variables is the body of the let. But when a variable is defined by a pattern matching or by an alias, what is the scope ? I suppose that it's the function, but I've not been able to find references of that in the core erlang 1.0.3 specifications. Concerning primop: is there a way to call these functions in erlang ? If not, is it possible to know all primops that are used by erlang compiler when generating core erlang ? As you may understand, I'm toying with writing a core erlang evaluator. Thanks Denis From ok Tue Oct 14 03:42:57 2008 From: ok (Richard O'Keefe) Date: Tue, 14 Oct 2008 14:42:57 +1300 Subject: [erlang-questions] Types and specs [WAS: [enhancement] string:split/2] In-Reply-To: <48F2EF67.7010005@cs.ntua.gr> References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> <48EF3D78.2060306@cs.ntua.gr> <795E68D8-738A-4EE5-88E4-0F607132026C@cs.otago.ac.nz> <48F2EF67.7010005@cs.ntua.gr> Message-ID: <4335FA0F-BE26-4000-B883-111F35F85058@cs.otago.ac.nz> On 13 Oct 2008, at 7:49 pm, Kostis Sagonas wrote: > Richard O'Keefe wrote: >> On 11 Oct 2008, at 12:33 am, Kostis Sagonas wrote that >> [[char(),...]] means list of non-empty strings, which >> is more precise than [string()]. >> Would [char()|string()] also work? > > No. This is a different type, which does not express what you want > here. > > Note that in the language of types | does not mean list tail, but > instead means type union. The above type denotes a (possibly empty) > list consisting of characters or strings. Then we have a rather nasty syntax problem here. If I had written [(char() | string()] where the bar is NOT part of the list syntax, I would certainly expect that to mean a list of things each of which is a char or a string. But with the vertical bar being part of the list syntax, I would expect [H | T] as a type to mean the type of cons cells whose heads are of type H and whose tails are of type T. If it *doesn't* mean that, it should be a syntax error. From kostis Tue Oct 14 08:41:47 2008 From: kostis (Kostis Sagonas) Date: Tue, 14 Oct 2008 09:41:47 +0300 Subject: [erlang-questions] Types and specs [WAS: [enhancement] string:split/2] In-Reply-To: <4335FA0F-BE26-4000-B883-111F35F85058@cs.otago.ac.nz> References: <6c2563b20810081642r2fbd1f14w8e3f7a5a2b71bcc4@mail.gmail.com> <48EF3D78.2060306@cs.ntua.gr> <795E68D8-738A-4EE5-88E4-0F607132026C@cs.otago.ac.nz> <48F2EF67.7010005@cs.ntua.gr> <4335FA0F-BE26-4000-B883-111F35F85058@cs.otago.ac.nz> Message-ID: <48F43F2B.2030308@cs.ntua.gr> Richard O'Keefe wrote: > > On 13 Oct 2008, at 7:49 pm, Kostis Sagonas wrote: > >> Richard O'Keefe wrote: >>> On 11 Oct 2008, at 12:33 am, Kostis Sagonas wrote that >>> [[char(),...]] means list of non-empty strings, which >>> is more precise than [string()]. >>> Would [char()|string()] also work? >> >> No. This is a different type, which does not express what you want here. >> >> Note that in the language of types | does not mean list tail, but >> instead means type union. The above type denotes a (possibly empty) >> list consisting of characters or strings. > > Then we have a rather nasty syntax problem here. > > If I had written [(char() | string()] where the bar is NOT > part of the list syntax, I would certainly expect that to > mean a list of things each of which is a char or a string. > But with the vertical bar being part of the list syntax, > I would expect [H | T] as a type to mean the type of cons > cells whose heads are of type H and whose tails are of type T. The language of types does not have any convenient notation for lists with a tail other than []. The [...] notation is a shorthand for list() and *always* refers to proper lists, so there's no ambiguity there. (If you want to specify an improper list the closer you can get is to employ the long and yucky type maybe_improper_list() that does not have any convenient shorthand. As its name suggests, you cannot even be specify with certainty that the list is improper.) > If it *doesn't* mean that, it should be a syntax error. I agree with you that the version with parentheses looks and feels better. You are welcome to submit a patch for this. Kostis From monch1962 Tue Oct 14 08:43:56 2008 From: monch1962 (David Mitchell) Date: Tue, 14 Oct 2008 17:43:56 +1100 Subject: [erlang-questions] What's the status of erl_com, the Erlang-to-COM bridge? Message-ID: Hello everyone, I've come across what used to be called the COMET project, or erl_com, which is a bridge between Erlang and COM on Windows. Unfortunately, all the info I can find on it is several years old, but it would be very useful to me if it was still usable, supportable, etc. Does anyone know the status of this project? Is it still active (and I haven't been able to find any recent docs)? Has it been replaced by something else? Does it still work in R11 or R12? Thanks in advance Dave M. From kostis Tue Oct 14 09:26:52 2008 From: kostis (Kostis Sagonas) Date: Tue, 14 Oct 2008 10:26:52 +0300 Subject: [erlang-questions] Why is query a reserved word In-Reply-To: References: Message-ID: <48F449BC.1020902@cs.ntua.gr> Lennart ?hman wrote: > Hi, > it was used in defining a Mnemosyne query - a now obsoleted Mnesia query language. I would have assumed that since Mnemosyne is now obsolete, 'query' would have stopped being a reserved word.... Kostis From richardc Tue Oct 14 09:33:12 2008 From: richardc (Richard Carlsson) Date: Tue, 14 Oct 2008 09:33:12 +0200 Subject: [erlang-questions] core erlang, scope, primop In-Reply-To: <349ebab60810131447x2391571ei4c01e5d4e6f5c091@mail.gmail.com> References: <349ebab60810131447x2391571ei4c01e5d4e6f5c091@mail.gmail.com> Message-ID: <48F44B38.6040300@it.uu.se> denis wrote: > I've two questions on core erlang: > > Concerning the scope of variables: when using let, the scope of the > variables is the body of the let. But when a variable is defined by a > pattern matching or by an alias, what is the scope ? I suppose that > it's the function, but I've not been able to find references of that > in the core erlang 1.0.3 specifications. This is described at the top of page 15, under "Case:". The scope is the body of the clause, and also the guard (follow the reference to section 6.6). (Core Erlang isolates all pattern matching to the case expressions, so things are a lot easier than in the full Erlang.) > Concerning primop: is there a way to call these functions in erlang ? > If not, is it possible to know all primops that are used by erlang > compiler when generating core erlang ? Not as such. As explained in section 7, the primops are only there to help on the implementation level, to represent internal operations that do not generally have a corresponding Erlang function somewhere. They are thus completely dependent on the compiler and VM implementation. However, the number of primops used by the OTP compiler is pretty small, and can be found rather quickly by inspecting some core code generated from typical Erlang source files and grepping under lib/compiler/src. > As you may understand, I'm toying with writing a core erlang evaluator. There should really have been an official interpreter, but I never got time to finish it. Have fun! /Richard From imre Tue Oct 14 10:46:03 2008 From: imre (Imre Palik) Date: Tue, 14 Oct 2008 11:46:03 +0300 Subject: [erlang-questions] generating primes Message-ID: <3BE6DBA1F3BE9D4798255806113D56540F78C912D5@utx-exchange.utx.local> Hi, I am playing with Project Euler nowdays, and in the last few problems I solved I had problems generating primes fast enough. Currently I am using the following implementation of the Sieve of Eratosthenes: sieve([]) -> []; sieve([H|T]) -> [H|sieve([X||X<-T,X rem H =/= 0])]. I tried to change it to use addition instead of doing the remainder: sieve_filter(_, _, []) -> []; sieve_filter(F, I, [F|T]) -> sieve_filter(F + I, I, T); sieve_filter(F, I, [H|T]) when H > F-> [H|sieve_filter(F + I, I, T)]; sieve_filter(F, I, [H|T]) -> [H|sieve_filter(F, I, T)]. sieve2([]) -> []; sieve2([H|T]) -> [H|sieve2(sieve_filter(3 * H, 2 * H, T))]. But this one runs slower than the original. Could anybody explain why? Are there any optimisations I can do here, or do I have to find a better algorithm (any pointers?)? Thanks Imre From roberto Tue Oct 14 11:42:04 2008 From: roberto (Roberto Aloi) Date: Tue, 14 Oct 2008 10:42:04 +0100 Subject: [erlang-questions] PDG Generation in Erlang Message-ID: <48F4696C.20406@erlang-consulting.com> Hello everyone, I'm trying to dynamically create a PDF file within an erlang server, sending it to a requesting client, but I couldn't find any library that support that. Any hint? Regards, Roberto Aloi From ulf Tue Oct 14 11:50:31 2008 From: ulf (Ulf Wiger) Date: Tue, 14 Oct 2008 11:50:31 +0200 Subject: [erlang-questions] PDG Generation in Erlang In-Reply-To: <48F4696C.20406@erlang-consulting.com> References: <48F4696C.20406@erlang-consulting.com> Message-ID: <8209f740810140250uec7b296w6eac0b0ea956080@mail.gmail.com> You could take a look at erlguten: http://code.google.com/p/erlguten/ BR, Ulf W 2008/10/14 Roberto Aloi : > Hello everyone, > I'm trying to dynamically create a PDF file within an erlang server, > sending it to a requesting client, but I couldn't find any library that > support that. > Any hint? > Regards, > > Roberto Aloi > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From roberto Tue Oct 14 12:10:09 2008 From: roberto (Roberto Aloi) Date: Tue, 14 Oct 2008 11:10:09 +0100 Subject: [erlang-questions] PDG Generation in Erlang In-Reply-To: <48F4696C.20406@erlang-consulting.com> References: <48F4696C.20406@erlang-consulting.com> Message-ID: <48F47001.2010402@erlang-consulting.com> It seems to be exactly what I was looking for. Cheers, Roberto Aloi From armstrong.whit Tue Oct 14 13:28:13 2008 From: armstrong.whit (Whit Armstrong) Date: Tue, 14 Oct 2008 07:28:13 -0400 Subject: [erlang-questions] Article on Erlang in ACM Queue In-Reply-To: <48EF60A6.10400@ericsson.com> References: <48ED943A.80801@berabera.info> <8ec76080810100621r48b0a482j1e02ad8bf5788a58@mail.gmail.com> <48EF60A6.10400@ericsson.com> Message-ID: <8ec76080810140428v3cf77612ofa0b4c488e51b21d@mail.gmail.com> Thanks for the feedback everyone. FFI looks very interesting. does Erlang make guarantees about storing data in contiguous memory? My guess is that the binary data type was designed with that in mind. However, do I understand correctly that floats cannot be stored in a binary data type? for instance: Eshell V5.6.3 (abort with ^G) 1> X = <<1,3,9>>. <<1,3,9>> 2> Y = <<1.0,3.0,9.0>>. ** exception error: bad argument 3> or am I missing something obvious? Can anyone refer me to the source file that defines binary data types? Thanks, Whit On Fri, Oct 10, 2008 at 10:03 AM, Ulf Wiger (TN/EAB) wrote: > Whit Armstrong skrev: >> >> I'm new to Erlang. I've been considering it for a few simulation >> projects in finance. However, I was discouraged because the ACM >> article suggests that Erlang has poor floating point performance. >> >> Are any list members using Erlang for numerical simulations? If so, >> do you have any advice on how to how to improve efficiency? What >> about using binaries to store vectors of doubles? Are there any >> extensions of Erlang that allow one to do that? > > Perhaps this might at least give you some initial intuition: > > High-performance Technical Computing with Erlang > Alceste Scalas Giovanni Casu Piero Pili > Center for Advanced Studies, Research and Development in Sardinia > ACM ICFP 2008 / Erlang Workshop > September 27th, 2008 > Victoria, BC, Canada > > http://www.erlang.org/workshop/2008/Sess23.pdf > > BR, > Ulf W > From armstrong.whit Tue Oct 14 13:31:05 2008 From: armstrong.whit (Whit Armstrong) Date: Tue, 14 Oct 2008 07:31:05 -0400 Subject: [erlang-questions] Article on Erlang in ACM Queue In-Reply-To: References: <48ED943A.80801@berabera.info> <8ec76080810100621r48b0a482j1e02ad8bf5788a58@mail.gmail.com> Message-ID: <8ec76080810140431i4264e06ala8c42a41b5f30e56@mail.gmail.com> Bill, Thanks for the code. Any chance that you have a quadratic optimization method defined in Erlang code? I'd be very curious to see how that problem is tackled in Erlang. Cheers, Whit On Fri, Oct 10, 2008 at 9:46 AM, Bill McKeeman wrote: > I think it depends on how much you can do in parallel and how much is really floating point as contrasted to function calls and the like. I wrote a numerical integration routine with a parameter N for the number of cores I expected to use. Even with N = 2 it was better than some competing sequential versions. I'll attach the code. > /s/Bill > > -----Original Message----- > From: erlang-questions-bounces [mailto:erlang-questions-bounces] On Behalf Of Whit Armstrong > Sent: Friday, October 10, 2008 9:22 AM > To: Erlang mailing list > Subject: Re: [erlang-questions] Article on Erlang in ACM Queue > > I'm new to Erlang. I've been considering it for a few simulation > projects in finance. However, I was discouraged because the ACM > article suggests that Erlang has poor floating point performance. > > Are any list members using Erlang for numerical simulations? If so, > do you have any advice on how to how to improve efficiency? What > about using binaries to store vectors of doubles? Are there any > extensions of Erlang that allow one to do that? > > Any feedback is appreciated. > > Thanks, > Whit > > > On Thu, Oct 9, 2008 at 1:18 AM, Romain Lenglet > wrote: >> Jim Larson has written an article entitled "Erlang for Concurrent >> Programming", published in the latest ACM Queue: >> http://mags.acm.org/queue/200809/ >> >> This article is a very good, practical introduction to Erlang and OTP. >> >> -- >> Romain Lenglet >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions >> http://www.erlang.org/mailman/listinfo/erlang-questions >> > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From freza Tue Oct 14 14:10:06 2008 From: freza (Jachym Holecek) Date: Tue, 14 Oct 2008 14:10:06 +0200 Subject: [erlang-questions] Article on Erlang in ACM Queue In-Reply-To: <8ec76080810140428v3cf77612ofa0b4c488e51b21d@mail.gmail.com> References: <48ED943A.80801@berabera.info> <8ec76080810100621r48b0a482j1e02ad8bf5788a58@mail.gmail.com> <48EF60A6.10400@ericsson.com> <8ec76080810140428v3cf77612ofa0b4c488e51b21d@mail.gmail.com> Message-ID: <20081014121006.GA1897@hanele.fractal2003.cz> # Whit Armstrong 2008-10-14: > Thanks for the feedback everyone. FFI looks very interesting. > [...] > Can anyone refer me to the source file that defines binary data types? erts/emulator/beam/erl_binary.h erts/emulator/beam/erl_term.h erts/emulator/beam/binary.c -- Jachym From florian.ebeling Tue Oct 14 15:01:36 2008 From: florian.ebeling (C. Florian Ebeling) Date: Tue, 14 Oct 2008 15:01:36 +0200 Subject: [erlang-questions] Specify version in release using woldcards? Message-ID: <5cbbe4ae0810140601r1c8da84ah72f52739f1c6cead@mail.gmail.com> Hi, we have an application on which two people are working using defferent kinds of unix/linux distributions (Mac and Suse). So they have deferent releases of erlang installed. When I use this release spec, I get warnings from make_script/2. {release, {"adrecord_rel","1.0"}, {erts, "5.6.3"}, [{kernel,"2.12.3"}, {stdlib,"1.15.3"}, {sasl, "2.1.5.3"}, {crypto, "1.5.2"}, {adrecord, "0.1"}]} which look like this: erl -noshell -pa ebin -eval 'systools:make_script("adrecord", [local])' -s init stop crypto: No valid version ("1.5.2") of .app file found. Found file "/opt/local/lib/erlang/lib/crypto-1.5.2.1/ebin/crypto.app" with version "1.5.2.1" Is there some elegant way to deal with this? Can I maybe specify some wildcards or only the more major part of versions? Florian -- Florian Ebeling Twitter: febeling florian.ebeling From anders.nygren Tue Oct 14 15:14:08 2008 From: anders.nygren (Anders Nygren) Date: Tue, 14 Oct 2008 08:14:08 -0500 Subject: [erlang-questions] Article on Erlang in ACM Queue In-Reply-To: <8ec76080810140428v3cf77612ofa0b4c488e51b21d@mail.gmail.com> References: <48ED943A.80801@berabera.info> <8ec76080810100621r48b0a482j1e02ad8bf5788a58@mail.gmail.com> <48EF60A6.10400@ericsson.com> <8ec76080810140428v3cf77612ofa0b4c488e51b21d@mail.gmail.com> Message-ID: On Tue, Oct 14, 2008 at 6:28 AM, Whit Armstrong wrote: > Thanks for the feedback everyone. FFI looks very interesting. > > does Erlang make guarantees about storing data in contiguous memory? > My guess is that the binary data type was designed with that in mind. > However, do I understand correctly that floats cannot be stored in a > binary data type? > > for instance: > > Eshell V5.6.3 (abort with ^G) > 1> X = <<1,3,9>>. > <<1,3,9>> > 2> Y = <<1.0,3.0,9.0>>. > ** exception error: bad argument > 3> > > or am I missing something obvious? > You need to tell the compiler that it is supposed to be floats. Like Y = <<1.0/float,3.0/float,9.0/float>>. <<63,240,0,0,0,0,0,0,64,8,0,0,0,0,0,0,64,34,0,0,0,0,0,0>> see the documentation, especially http://erlang.org/doc/programming_examples/bit_syntax.html#4 for more details /Anders > Can anyone refer me to the source file that defines binary data types? > > Thanks, > Whit > > > > > On Fri, Oct 10, 2008 at 10:03 AM, Ulf Wiger (TN/EAB) > wrote: >> Whit Armstrong skrev: >>> >>> I'm new to Erlang. I've been considering it for a few simulation >>> projects in finance. However, I was discouraged because the ACM >>> article suggests that Erlang has poor floating point performance. >>> >>> Are any list members using Erlang for numerical simulations? If so, >>> do you have any advice on how to how to improve efficiency? What >>> about using binaries to store vectors of doubles? Are there any >>> extensions of Erlang that allow one to do that? >> >> Perhaps this might at least give you some initial intuition: >> >> High-performance Technical Computing with Erlang >> Alceste Scalas Giovanni Casu Piero Pili >> Center for Advanced Studies, Research and Development in Sardinia >> ACM ICFP 2008 / Erlang Workshop >> September 27th, 2008 >> Victoria, BC, Canada >> >> http://www.erlang.org/workshop/2008/Sess23.pdf >> >> BR, >> Ulf W >> > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From alceste Tue Oct 14 14:15:38 2008 From: alceste (Alceste Scalas) Date: Tue, 14 Oct 2008 14:15:38 +0200 Subject: [erlang-questions] Article on Erlang in ACM Queue In-Reply-To: <8ec76080810140428v3cf77612ofa0b4c488e51b21d@mail.gmail.com> References: <48ED943A.80801@berabera.info> <8ec76080810100621r48b0a482j1e02ad8bf5788a58@mail.gmail.com> <48EF60A6.10400@ericsson.com> <8ec76080810140428v3cf77612ofa0b4c488e51b21d@mail.gmail.com> Message-ID: <1223986538.8191.71.camel@gnatziu> Il giorno mar, 14/10/2008 alle 07.28 -0400, Whit Armstrong ha scritto: > does Erlang make guarantees about storing data in contiguous memory? > My guess is that the binary data type was designed with that in mind. Yes, binary data is guaranteed to be stored in contiguous memory. See: http://erlang.org/doc/reference_manual/data_types.html#2.4 > However, do I understand correctly that floats cannot be stored in a > binary data type? Sure they can, just try with: %% Single precision Y1 = <<1.0:32/native-float, 2.0:32/native-float, 3.0:32/native-float>>. %% Double precision Y2 = <<1.0:64/native-float, 2.0:64/native-float, 3.0:64/native-float>>. More details on: http://erlang.org/doc/reference_manual/expressions.html#bit_syntax Regards, -- Alceste Scalas CRS4 - http://www.crs4.it/ From harveyd Tue Oct 14 15:36:05 2008 From: harveyd (Dale Harvey) Date: Tue, 14 Oct 2008 14:36:05 +0100 Subject: [erlang-questions] Specify version in release using woldcards? In-Reply-To: <5cbbe4ae0810140601r1c8da84ah72f52739f1c6cead@mail.gmail.com> References: <5cbbe4ae0810140601r1c8da84ah72f52739f1c6cead@mail.gmail.com> Message-ID: might not be the best solution, but I just build the spec file dynamically before building the boot script get_vsn(Module) -> AppFile = code:lib_dir(Module)++"/ebin/"++atom_to_list(Module)++".app", {ok,[{application,_App,Attrs}]} = file:consult(AppFile), {value,{vsn,Vsn}} = lists:keysearch(vsn,1,Attrs), Vsn get_vsn(crypto) will then get you the installed version of crypto use get_vsn and erlang:system_info(version) to build the spec file, write it, and then call make_script 2008/10/14 C. Florian Ebeling > Hi, > > we have an application on which two people are working > using defferent kinds of unix/linux distributions (Mac and Suse). > > So they have deferent releases of erlang installed. When > I use this release spec, I get warnings from make_script/2. > > {release, {"adrecord_rel","1.0"}, {erts, "5.6.3"}, > [{kernel,"2.12.3"}, > {stdlib,"1.15.3"}, > {sasl, "2.1.5.3"}, > {crypto, "1.5.2"}, > {adrecord, "0.1"}]} > > which look like this: > > erl -noshell -pa ebin -eval 'systools:make_script("adrecord", > [local])' -s init stop > crypto: No valid version ("1.5.2") of .app file found. Found file > "/opt/local/lib/erlang/lib/crypto-1.5.2.1/ebin/crypto.app" with > version "1.5.2.1" > > Is there some elegant way to deal with this? Can I maybe > specify some wildcards or only the more major part of versions? > > Florian > > > -- > Florian Ebeling > Twitter: febeling > florian.ebeling > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081014/09796132/attachment.html From florian.ebeling Tue Oct 14 15:42:05 2008 From: florian.ebeling (C. Florian Ebeling) Date: Tue, 14 Oct 2008 15:42:05 +0200 Subject: [erlang-questions] Specify version in release using woldcards? In-Reply-To: References: <5cbbe4ae0810140601r1c8da84ah72f52739f1c6cead@mail.gmail.com> Message-ID: <5cbbe4ae0810140642j20a13ee2n353f9660cdd69b67@mail.gmail.com> On Tue, Oct 14, 2008 at 3:36 PM, Dale Harvey wrote: > might not be the best solution, but I just build the spec file dynamically > before building the boot script > > get_vsn(Module) -> > AppFile = code:lib_dir(Module)++"/ebin/"++atom_to_list(Module)++".app", > {ok,[{application,_App,Attrs}]} = file:consult(AppFile), > {value,{vsn,Vsn}} = lists:keysearch(vsn,1,Attrs), > Vsn > > get_vsn(crypto) will then get you the installed version of crypto > > use get_vsn and erlang:system_info(version) to build the spec file, > write it, and then call make_script yes, I was kind of hoping to avoid that route :) Anyway, thanks for posting the details how to do that. Florian -- Florian Ebeling Twitter: febeling florian.ebeling From devdoer2 Tue Oct 14 15:56:13 2008 From: devdoer2 (devdoer bird) Date: Tue, 14 Oct 2008 21:56:13 +0800 Subject: [erlang-questions] Failed to fetch .app file when using "-loader inet" and erl_boot_server Message-ID: HI: I decide to run a diskless node and let it fetch code from a remote machine. I accomplish this by using erl_boot_server and starting the remote node with "-loader inet -hosts" parameters. It is ok to fetch code from the code server node on which erl_boot_server is started, but the .app file is failed to fetch. It report the error "{error,{"no such file or directory","some_application.app"}}" . So how can I configure the boot server to let it run a application on the remote diskless node If the application's app file can't be passed to the remote node? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081014/9d82227c/attachment-0001.html From erlang Tue Oct 14 17:31:02 2008 From: erlang (Joe Armstrong) Date: Tue, 14 Oct 2008 17:31:02 +0200 Subject: [erlang-questions] Finding inconsistencies in record definitions and pretty printing records Message-ID: <9b08084c0810140831s5d8e1828x1e9a836b17951fc5@mail.gmail.com> Hi, This is a method for ensuring the consistency of records and for providing record field information at run-time. Long-time readers of this list will recognize this as a long-standing problem. (what's the problem? if you change a record definition and forget to recompile everything you will get fried - and record definitions get forgotten at run time) (Short summary of how it works) - compile record definitions into the modules (uses a simple parse transform) - hack the error_handler so that every time a new module is loaded the record definitions in the module are sent to a global server that remembers all record definitions - make a global sever to check the consistency of the record definitions - start things off the right way ... (The long version) Here's what I do: 1) make a parse transform that compiles all local and included record definitions into a file. If you include the line: -compile({parse_transform, jalib_records}). In your code then an extra function called module_records() -> ... will be included into the compiled code for your module. 2) Change error_handler.erl The old code: ensure_loaded(Module) -> Self = self(), case whereis(code_server) of %% Perhaps double fault should be detected in code:ensure_loaded/1 %% instead, since this error handler cannot know whether the %% code server can resolve the problem or not. %% An {error, Reason} return from there would crash the code server and %% bring down the node. Self -> Error = "The code server called the unloaded module `" ++ atom_to_list(Module) ++ "'", halt(Error); Pid when is_pid(Pid) -> code:ensure_loaded(Module); _ -> init:ensure_loaded(Module) end. Is changed to: ensure_loaded(Module) -> Self = self(), case whereis(code_server) of %% Perhaps double fault should be detected in code:ensure_loaded/1 %% instead, since this error handler cannot know whether the %% code server can resolve the problem or not. %% An {error, Reason} return from there would crash the code server and %% bring down the node. Self -> Error = "The code server called the unloaded module `" ++ atom_to_list(Module) ++ "'", halt(Error); Pid when is_pid(Pid) -> Val = code:ensure_loaded(Module), run_on_load(Module), %% **** NEW STUFF Val; _ -> init:ensure_loaded(Module) end. Where run_on_load(Mod) -> case erlang:function_exported(Mod, module_records, 0) of true -> Records = Mod:module_records(), %% assume a registered process %% jalib_records that keeps track of all records (catch jalib_records ! {loaded, Mod, Records}); false -> void end. 3) jalib_records.erl also has a server that keeps track of the records. So I have to start this somehow. I added these lines to my ${HOME}/.erlang (catch jalib_records:start()). code:unstick_mod(error_handler). code:load_abs("/home/joe/code/jalib/error_handler"). io:format("new error handler loaded~n"). Now we're ready to test 0) compile error_handler.erl and jalib_records.erl and put in your path. a) Here's a module with some records -module(rec_test1). -compile(export_all). -compile({parse_transform, jalib_records}). -record(foo, {a=1,b=2,c=[]}). -record(bar, {x=2,y=23}). foo() -> {#foo{}, #bar{}}. test() -> jalib_records:print_record(#foo{a=hello}). b) and rec_test2.erl -module(rec_test2). -compile(export_all). -compile({parse_transform, jalib_records}). -record(foo, {a=1,b=2,c=[]}). -record(bar, {x=2,y=23,z=6}). foo() -> {#foo{}, #bar{}}. test() -> jalib_records:print_record(#foo{a=hello}). c) Compile both: erlc rec_test1.erl rec_test2.erl d) run in the shell 1> rec_test1:test(). "#foo{a = hello,b = 2,c = []}" It works 2> rec_test2:test(). *** Record definition error: Record:bar Old Mod:rec_test1 definition:[{x,2},{y,23}] New Mod:rec_test2 definition:[{x,2},{y,23},{z,6}] "#foo{a = hello,b = 2,c = []}" Yes - we detect that the module definition of bar is inconsistent. This is a quick and dirty prototype - which shows that the method works. For a production version some improvements are necessary: - make it work for incremental code loading (it only works the first time you load a module) - improve error messages (ie make uniform with OTP standards) - improve pretty printer Have fun /Joe Armstrong -------------- next part -------------- A non-text attachment was scrubbed... Name: jalib_records.erl Type: application/octet-stream Size: 3612 bytes Desc: not available Url : http://www.erlang.org/pipermail/erlang-questions/attachments/20081014/02a6b61d/attachment.obj -------------- next part -------------- A non-text attachment was scrubbed... Name: error_handler.erl Type: application/octet-stream Size: 4461 bytes Desc: not available Url : http://www.erlang.org/pipermail/erlang-questions/attachments/20081014/02a6b61d/attachment-0001.obj -------------- next part -------------- A non-text attachment was scrubbed... Name: rec_test1.erl Type: application/octet-stream Size: 234 bytes Desc: not available Url : http://www.erlang.org/pipermail/erlang-questions/attachments/20081014/02a6b61d/attachment-0002.obj -------------- next part -------------- A non-text attachment was scrubbed... Name: rec_test2.erl Type: application/octet-stream Size: 238 bytes Desc: not available Url : http://www.erlang.org/pipermail/erlang-questions/attachments/20081014/02a6b61d/attachment-0003.obj From ulf.wiger Tue Oct 14 17:51:07 2008 From: ulf.wiger (Ulf Wiger (TN/EAB)) Date: Tue, 14 Oct 2008 17:51:07 +0200 Subject: [erlang-questions] Finding inconsistencies in record definitions and pretty printing records In-Reply-To: <9b08084c0810140831s5d8e1828x1e9a836b17951fc5@mail.gmail.com> References: <9b08084c0810140831s5d8e1828x1e9a836b17951fc5@mail.gmail.com> Message-ID: <48F4BFEB.4050803@ericsson.com> Joe Armstrong skrev: > > For a production version some improvements are necessary: > > - ... > - improve pretty printer Therer is already a good pretty printer of records in OTP: io_lib_pretty:print(Term, Column, LineLength, Depth, RecDefFun) where Column is typically 1, LineLength = 30 in the shell, and RecDefFun = fun(Tag, N_fields) -> [Field_name] | no See shell.erl for how it's used. I played around with it here: http://ulf.wiger.net/weblog/2007/11/20/extending-the-erlang-shell-part-1/ BR, Ulf W From erlang Tue Oct 14 21:57:49 2008 From: erlang (Joe Armstrong) Date: Tue, 14 Oct 2008 21:57:49 +0200 Subject: [erlang-questions] Finding inconsistencies in record definitions and pretty printing records In-Reply-To: <87vdvv6tkb.fsf@sterlett.hq.kred> References: <9b08084c0810140831s5d8e1828x1e9a836b17951fc5@mail.gmail.com> <87vdvv6tkb.fsf@sterlett.hq.kred> Message-ID: <9b08084c0810141257o651f363fx82dddfe0749cbe97@mail.gmail.com> On Tue, Oct 14, 2008 at 6:16 PM, mats cronqvist wrote: > "Joe Armstrong" writes: > >> Hi, >> >> This is a method for ensuring the consistency of records and for >> providing record field information at run-time. >> >> Long-time readers of this list will recognize this as a long-standing >> problem. >> >> (what's the problem? if you change a record definition and >> forget to recompile everything you will get fried - and >> record definitions get forgotten at run time) >> >> (Short summary of how it works) >> >> - compile record definitions into the modules >> (uses a simple parse transform) > > this is the problematic bit. as has been hashed several times on > this list, were record info exported (perhaps as a field in > module_info), all kinds of cool things could be accomplished. It's not problematic - the parse transform in the enclosed code does exactly that. The enclosed code compiles record defs into the modules concerned - sets up the servers, detects module inconsitencies at run time and retrieves record definitions at run time *from any module* (not just the definition module). As far as I can see it is ready to include in a production version - except for a slight improvement to the pretty printer and to make sure the definitions are reloaded when we recompile a module. A slight (and obvious) change makes all kind of dynamic (and generic) record operations possible. ie things like doing X#rec{a=A} at run time *in any module* when the module concerned did not have knowledge of #rec at compile time. (hint change the parse transform to make an efficient form of module_record so that calling module_record(rec, a) -> 1 (or whatever) the "trick" is in finding which module #rec came from - and this is solved in the enclosed code. (With a simple optimization in the beam (hint - cache the module, once it it is known) this would be pretty efficient). /Joe > > mats > From erlang Tue Oct 14 21:59:44 2008 From: erlang (Joe Armstrong) Date: Tue, 14 Oct 2008 21:59:44 +0200 Subject: [erlang-questions] Finding inconsistencies in record definitions and pretty printing records In-Reply-To: <48F4BFEB.4050803@ericsson.com> References: <9b08084c0810140831s5d8e1828x1e9a836b17951fc5@mail.gmail.com> <48F4BFEB.4050803@ericsson.com> Message-ID: <9b08084c0810141259h68cbf74ch76d1bc36ef794fd1@mail.gmail.com> Thanks - so now I can hack this to fetch RecDefFun at run-time :-) /Joe On Tue, Oct 14, 2008 at 5:51 PM, Ulf Wiger (TN/EAB) wrote: > Joe Armstrong skrev: >> >> For a production version some improvements are necessary: >> >> - ... >> - improve pretty printer > > Therer is already a good pretty printer of records in OTP: > io_lib_pretty:print(Term, Column, LineLength, Depth, RecDefFun) > > where Column is typically 1, LineLength = 30 in the shell, > and RecDefFun = fun(Tag, N_fields) -> [Field_name] | no > > See shell.erl for how it's used. > > I played around with it here: > http://ulf.wiger.net/weblog/2007/11/20/extending-the-erlang-shell-part-1/ > > BR, > Ulf W > From kenneth.lundin Tue Oct 14 23:52:27 2008 From: kenneth.lundin (Kenneth Lundin) Date: Tue, 14 Oct 2008 23:52:27 +0200 Subject: [erlang-questions] What's the status of erl_com, the Erlang-to-COM bridge? In-Reply-To: References: Message-ID: Hi, The Comet application did never reach more than alfa or maybe beta status before we stopped the development due to no customers for it. We had to prioritize other things instead. It has not been maintained or even used for maybe 7 years or more now. It will for sure not even build toegther with the latest release (R12B). I have no idea how much work it will be to get it in a useful state. We have no plans to work with it. /Kenneth Erlang/OTP team , Ericsson On Tue, Oct 14, 2008 at 8:43 AM, David Mitchell wrote: > Hello everyone, > > I've come across what used to be called the COMET project, or erl_com, > which is a bridge between Erlang and COM on Windows. Unfortunately, > all the info I can find on it is several years old, but it would be > very useful to me if it was still usable, supportable, etc. > > Does anyone know the status of this project? Is it still active (and > I haven't been able to find any recent docs)? Has it been replaced by > something else? Does it still work in R11 or R12? > > Thanks in advance > > Dave M. > _______________________________________________ > erlang-questions mailing list > erlang-questions > http://www.erlang.org/mailman/listinfo/erlang-questions > From monch1962 Wed Oct 15 06:52:24 2008 From: monch1962 (David Mitchell) Date: Wed, 15 Oct 2008 15:52:24 +1100 Subject: [erlang-questions] What's the status of erl_com, the Erlang-to-COM bridge? In-Reply-To: References: Message-ID: Thanks Jakob and Kenneth for your responses. I need to hook Erlang to a variety of external applications (MQ, Tibco Rendezvous, Oracle), none of which have "native" Erlang interfaces but all have COM interfaces available. Comet looked like a good fit (assuming I ran Erlang on a Windows box), but based on your comments I'll look elsewhere. That probably means building a C port for MQ and Tibco, and I may be able to get away with using ODBC for Oracle. If you need any votes of support to revive COMET within Ericsson, please let me know ;-> Thanks again Dave M. 2008/10/15 Kenneth Lundin : > Hi, > > The Comet application did never reach more than alfa or maybe beta > status before we stopped the development due to > no customers for it. We had to prioritize other things instead. > It has not been maintained or even used for maybe 7 years or more now. > It will for sure not even build toegther with the latest release (R12B). > I have no idea how much work it will be to get it in a useful state. > > We have no plans to work with it. > > /Kenneth Erlang/OTP team , Ericsson > > On Tue, Oct 14, 2008 at 8:43 AM, David Mitchell wrote: >> Hello everyone, >> >> I've come across what used to be called the COMET project, or erl_com, >> which is a bridge between Erlang and COM on Windows. Unfortunately, >> all the info I can find on it is several years old, but it would be >> very useful to me if it was still usable, supportable, etc. >> >> Does anyone know the status of this project? Is it still active (and >> I haven't been able to find any recent docs)? Has it been replaced by >> something else? Does it still work in R11 or R12? >> >> Thanks in advance >> >> Dave M. >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions >> http://www.erlang.org/mailman/listinfo/erlang-questions >> > From jeffm Wed Oct 15 07:46:00 2008 From: jeffm (jm) Date: Wed, 15 Oct 2008 16:46:00 +1100 Subject: [erlang-questions] Q: Differenciating between List and List of Lists Message-ID: <48F58398.6040801@ghostgun.com> What is the best way to tell the difference between a list and a list of lists (possible in a guard)? What I'm trying to differentiate between is a string, eg, "astring" and a list of strings, eg ["a", "list", "of", "strings"]. Jeff. From jerome Wed Oct 15 08:05:47 2008 From: jerome (=?ISO-8859-1?Q?J=E9r=F4me_Desquilbet?=) Date: Wed, 15 Oct 2008 08:05:47 +0200 Subject: [erlang-questions] generating primes In-Reply-To: <3BE6DBA1F3BE9D4798255806113D56540F78C912D5@utx-exchange.utx.local> References: <3BE6DBA1F3BE9D4798255806113D56540F78C912D5@utx-exchange.utx.local> Message-ID: <48F5883B.8080607@desquilbet.org> Imre Palik a ?crit : > Hi, > > I am playing with Project Euler nowdays, and in the last few problems > I solved I had problems generating primes fast enough. Currently I > am using the following implementation of the Sieve of Eratosthenes: > > sieve([]) -> []; sieve([H|T]) -> [H|sieve([X||X<-T,X rem H =/= 0])]. > > ... Would you like a suboptimal algorithm? Here it is: N primes --> N sieves --> N erlang processes. It's all about playing after all... :-) J?r?me. PS: it's translated from an Ada example from Alan Burns and Andy Wellings. -----8<-------------------------- -module(eratosthenes). -export([message_logger/0, run/0, prime_collector/0, process_next_numbers/2, start_sieve/2, wait_for_next_prime/1]). message_logger() -> receive {prime_msg, P} -> io:format("~p is prime!~n", [P]), message_logger() end. prime_collector() -> receive Prime -> logger ! {prime_msg, Prime}, prime_collector() end. run() -> register(logger, spawn(?MODULE, message_logger, [])), Collector = spawn(?MODULE, prime_collector, []), Collector ! 1, Collector ! 2, First_Sieve = spawn(?MODULE, start_sieve, [3, Collector]), give_odd(5, First_Sieve). give_odd(Odd, First_Sieve) -> First_Sieve ! Odd, give_odd(Odd+2, First_Sieve). start_sieve(Prime, Collector) -> Collector ! Prime, Next_Prime = wait_for_next_prime(Prime), Next_Sieve = spawn(?MODULE, start_sieve, [Next_Prime, Collector]), process_next_numbers(Prime, Next_Sieve). wait_for_next_prime(Current_Prime) -> receive Odd -> if Odd rem Current_Prime == 0 -> wait_for_next_prime(Current_Prime); true -> Odd end end. process_next_numbers(Current_Prime, Next_Sieve) -> receive Odd -> if Odd rem Current_Prime /= 0 -> Next_Sieve ! Odd; true -> false end, process_next_numbers(Current_Prime, Next_Sieve) end. -----8<-------------------------- From vladdu55 Wed Oct 15 08:22:08 2008 From: vladdu55 (Vlad Dumitrescu) Date: Wed, 15 Oct 2008 08:22:08 +0200 Subject: [erlang-questions] Finding inconsistencies in record definitions and pretty printing records In-Reply-To: <9b08084c0810141257o651f363fx82dddfe0749cbe97@mail.gmail.com> References: <9b08084c0810140831s5d8e1828x1e9a836b17951fc5@mail.gmail.com> <87vdvv6tkb.fsf@sterlett.hq.kred> <9b08084c0810141257o651f363fx82dddfe0749cbe97@mail.gmail.com> Message-ID: <95be1d3b0810142322o684e4ac2xa148dfc8f1b1b99f@mail.gmail.com> Hi, On Tue, Oct 14, 2008 at 21:57, Joe Armstrong wrote: > On Tue, Oct 14, 2008 at 6:16 PM, mats cronqvist >> "Joe Armstrong" writes: >>> - compile record definitions into the modules >>> (uses a simple parse transform) >> >> this is the problematic bit. as has been hashed several times on >> this list, were record info exported (perhaps as a field in >> module_info), all kinds of cool things could be accomplished. > > It's not problematic - the parse transform in the enclosed code does > exactly that. > > The enclosed code compiles record defs into the modules > concerned - sets up the servers, detects module inconsitencies at run > time and retrieves record definitions at run time *from any module* > (not just the definition module). This is cool! Am I right that the "any module" above should be "any module compiled with this parse_transform"? If yes, it restricts a little working with legacy code, but it's still cool :-) regards, Vlad From vlm Wed Oct 15 08:23:14 2008 From: vlm (Lev Walkin) Date: Wed, 15 Oct 2008 10:23:14 +0400 Subject: [erlang-questions] Q: Differenciating between List and List of Lists In-Reply-To: <48F58398.6040801@ghostgun.com> References: <48F58398.6040801@ghostgun.com> Message-ID: <48F58C52.5070609@lionet.info> jm wrote: > What is the best way to tell the difference between a list and a list of > lists (possible in a guard)? What I'm trying to differentiate between is > a string, eg, "astring" and a list of strings, eg ["a", "list", "of", > "strings"]. Differentiating between just these two is easy, provided that the lists are non-empty: classify([I|_]) when is_integer(I) -> string; classify([L|_]) when is_list(L) -> list. in guard: just try the is_list/is_integer on the first element. However, look out for lists which aren't strings or lists of lists, such as [123,[def],$g,$h]. Hopefully you don't use them in your particular application. -- Lev Walkin vlm From erlang Wed Oct 15 08:45:57 2008 From: erlang (Joe Armstrong) Date: Wed, 15 Oct 2008 08:45:57 +0200 Subject: [erlang-questions] Finding inconsistencies in record definitions and pretty printing records In-Reply-To: <95be1d3b0810142322o684e4ac2xa148dfc8f1b1b99f@mail.gmail.com> References: <9b08084c0810140831s5d8e1828x1e9a836b17951fc5@mail.gmail.com> <87vdvv6tkb.fsf@sterlett.hq.kred> <9b08084c0810141257o651f363fx82dddfe0749cbe97@mail.gmail.com> <95be1d3b0810142322o684e4ac2xa148dfc8f1b1b99f@mail.gmail.com> Message-ID: <9b08084c0810142345j64bc24e6m2fe5b184ee6ffc91@mail.gmail.com> On Wed, Oct 15, 2008 at 8:22 AM, Vlad Dumitrescu wrote: > Hi, > > On Tue, Oct 14, 2008 at 21:57, Joe Armstrong wrote: >> On Tue, Oct 14, 2008 at 6:16 PM, mats cronqvist >>> "Joe Armstrong" writes: >>>> - compile record definitions into the modules >>>> (uses a simple parse transform) >>> >>> this is the problematic bit. as has been hashed several times on >>> this list, were record info exported (perhaps as a field in >>> module_info), all kinds of cool things could be accomplished. >> >> It's not problematic - the parse transform in the enclosed code does >> exactly that. >> >> The enclosed code compiles record defs into the modules >> concerned - sets up the servers, detects module inconsitencies at run >> time and retrieves record definitions at run time *from any module* >> (not just the definition module). > > This is cool! > > Am I right that the "any module" above should be "any module compiled > with this parse_transform"? If yes, it restricts a little working with > legacy code, but it's still cool :-) Yes - you have to recompile the modules erlc +'{parse_transform, jalib_records}' *.erl The point to recognise is that you have to add an "on_load" trigger - that puts the record definition into a *global* store of some kind. In fact It might be better to do this ensure_loaded(Module) -> Self = self(), case whereis(code_server) of Self -> Error = "The code server called the unloaded module `" ++ atom_to_list(Module) ++ "'", halt(Error); Pid when is_pid(Pid) -> Val = code:ensure_loaded(Module), (catch load_daemon ! {loaded, Module}), %% <---- the nifty bit Val; _ -> init:ensure_loaded(Module) end. Then if there is a registered load_daemon process it can do whatever it likes, for example receive {loaded, Mod} -> case erlang:function_exported(Mod, auto_exec_bat, 0) of true -> spawn(fun() -> Mod:auto_exec_bat() end); false -> void end , ... Loading a module is so important that perhaps it deserves a standard trigger ! /Joe > > regards, > Vlad > From tom Wed Oct 15 08:40:59 2008 From: tom (Tom Samplonius) Date: Tue, 14 Oct 2008 23:40:59 -0700 (PDT) Subject: [erlang-questions] Erlang with MonetDb In-Reply-To: <3bb44c6e0810080607m21ce8ef3o2d8fdfc054a9346d@mail.gmail.com> Message-ID: <12493306.9051224052859119.JavaMail.root@ly.sdf.com> ... > Well, in case it turns out we don't want to use it does anyone have a > good column store that they can recommend to use in conjunction with > Erlang? > > Cheers, > Bryan Rasmussen Maybe Scalaris? http://code.google.com/p/scalaris/ Tom From ulf.wiger Wed Oct 15 08:56:58 2008 From: ulf.wiger (Ulf Wiger (TN/EAB)) Date: Wed, 15 Oct 2008 08:56:58 +0200 Subject: [erlang-questions] Finding inconsistencies in record definitions and pretty printing records In-Reply-To: <9b08084c0810141259h68cbf74ch76d1bc36ef794fd1@mail.gmail.com> References: <9b08084c0810140831s5d8e1828x1e9a836b17951fc5@mail.gmail.com> <48F4BFEB.4050803@ericsson.com> <9b08084c0810141259h68cbf74ch76d1bc36ef794fd1@mail.gmail.com> Message-ID: <48F5943A.6000004@ericsson.com> Joe Armstrong skrev: > Thanks - so now I can hack this to fetch RecDefFun at run-time :-) > > /Joe The shell already fetches the record definitions at run-time, so no need to hack io_lib_pretty... ...although I did, of course, but that was just to support custom formatting of complex data structures, such as: 3> dict:from_list([{N,a} || N <- lists:seq(1,5)]). <|dict:[{3,a},{2,a},{5,a},{1,a},{4,a}]|> BR, Ulf W > > > On Tue, Oct 14, 2008 at 5:51 PM, Ulf Wiger (TN/EAB) > wrote: >> Joe Armstrong skrev: >>> For a production version some improvements are necessary: >>> >>> - ... >>> - improve pretty printer >> Therer is already a good pretty printer of records in OTP: >> io_lib_pretty:print(Term, Column, LineLength, Depth, RecDefFun) >> >> where Column is typically 1, LineLength = 30 in the shell, >> and RecDefFun = fun(Tag, N_fields) -> [Field_name] | no >> >> See shell.erl for how it's used. >> >> I played around with it here: >> http://ulf.wiger.net/weblog/2007/11/20/extending-the-erlang-shell-part-1/ >> >> BR, >> Ulf W >> From chn.dao77 Wed Oct 15 10:46:31 2008 From: chn.dao77 (WS Dao) Date: Wed, 15 Oct 2008 16:46:31 +0800 Subject: [erlang-questions] OTP float error on ARM. Message-ID: I cross-compiled OTP R12B4 for my ARM9 platform (S3C2410, kernel 2.4.18) When I run erl on arm, float error occurs: # ./erl Eshell V5.6.4 (abort with ^G) 1> 3+5. 8 2> 3.0. 0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005307579804 3> 3.0+4.0. 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000531405562 4> My toolchain is gcc 3.4.5. I'd wrote a c test program and cross-compile it, no float problems found. Any suggestion? -dao -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.erlang.org/pipermail/erlang-questions/attachments/20081015/4de5cf3e/attachment.html From roberto Wed Oct 15 10:57:29 2008 From: roberto (Roberto Aloi) Date: Wed, 15 Oct 2008 09:57:29 +0100 Subject: [erlang-questions] Q: Differenciating between List and List of Lists In-Reply-To: <48F58398.6040801@ghostgun.com> References: <48F58398.6040801@ghostgun.com> Message-ID: <48F5B079.6060808@erlang-consulting.com> > What is the