From diginux@REDACTED Sun Apr 1 01:48:32 2007 From: diginux@REDACTED (Jordan Wilberding) Date: Sat, 31 Mar 2007 18:48:32 -0500 Subject: [erlang-questions] How to identify symlinks with Erlang In-Reply-To: <460ECDB5.4060207@diginux.net> References: <460ECDB5.4060207@diginux.net> Message-ID: <460EF350.1080905@diginux.net> I ended up finding a solution. I wrote my own function, but instead of using file:read_file_info, I used file:read_link_info which correctly identifies symlink types along with files and directories. Thanks! Jordan Wilberding Jordan Wilberding wrote: > Hello, > > I was wondering if there is a way to identify if a directory is a > symlink to another directory in Erlang? > > The problem I am having is that when you install the wine, it creates > symlinks like > > ~/.wine/dosdevices/z: -> / > > This means when you try to use filelib:fold_files("~/.",..) it goes > endlessly, since it keeps recursing back into the symlink. > > Anyone have any ideas? > > Thanks! > Jordan Wilberding > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From fredrik.hoback@REDACTED Sun Apr 1 11:20:52 2007 From: fredrik.hoback@REDACTED (Fredrik Hoback) Date: Sun, 1 Apr 2007 11:20:52 +0200 Subject: [erlang-questions] Start module Message-ID: Hi, I have a project that I'm working on which consists of several modules. These has to be loaded ( l(my_module). ) and started in a special order. Since I have 5 modules it is cumbersome to do this every time. Is it possible to construct a new module that does this? It should first load some modules then start them? ------------------------------------ Fredrik Hoback fredrik.hoback@REDACTED -------------- next part -------------- An HTML attachment was scrubbed... URL: From rdiaz02@REDACTED Sun Apr 1 18:43:11 2007 From: rdiaz02@REDACTED (Ramon Diaz-Uriarte) Date: Sun, 1 Apr 2007 18:43:11 +0200 Subject: [erlang-questions] Erlang and Ada In-Reply-To: References: <624934630703290300v7e489ee2tad98c065e523f861@mail.gmail.com> Message-ID: <624934630704010943p71a225e2jaf66cd1830973f62@mail.gmail.com> On 3/30/07, ok wrote: > On 29 Mar 2007, at 10:00 pm, Ramon Diaz-Uriarte wrote: > > > I was looking for a comparison of Erlang with Ada and could find very > > little (I searched comp.lang.ada, the erlang list, and lambda the > > ultimate, and did a variety of goodle searches). I understand that the > > two languages have different origins and have been mainly applied in > > different areas (telecom --Erlang-- vs. aviation and military --Ada). > > But it seems both are unique among "major languages" in the support > > they provide for concurrent and distributed programming using message > > passing. Why, then, so few comparisons among the two? > > I have copies of the Ada 81, Ada 83, Ada 95, and Ada 2005 standards. > I haven't finished reading the last of these, as I only got it recently. > However, I can certainly assure you that there is nothing in any of the > previous Ada standards concerning distribution. Ada was designed to be Aha, I see. You obviously know this stuff, so I won't argue, but I thought in Appendix E (for Ada 95) there was some stuff related to/relevant for distribution. Anyway, you make this clear enough, and now that I reread some of my Ada material, I can find "concurrent" and parallel, but nothing that would indicate distributed. So I guess I managed to confuse myself. > a clean general-purpose programming language with a special emphasis on > embedded systems, which is one reason why the Ada standards do not > require > garbage collection. The SPARK Ada subset, that is, the subset supported > by the SPARK verifier, doesn't even include dynamic allocation, although > that is certainly part of the full language. > > Nor does Ada use message passing. It uses the *rendezvous*, which is > a bit like message passing except that it is synchronous and unbuffered. > If one Ada task wants another task to do something, it has to wait until > the other task is ready to receive the request. The 'select' statement > of Ada is very similar indeed to Erlang's 'receive', but the one is > unbuffered synchronous and the other buffered asynchronous. > Thanks for the clarification! > The different backgrounds lead to another important difference. > Erlang is designed for systems where you expect to upgrade the software > while it is running without taking the system down; this is the famous > "hot loading", and amongst other things it presupposes a network over > which the changes can be distributed. Ada was designed for conventional > applications and for embedded systems, where you are expected to follow > a development process that gets the program "right the first time". > There > is no notion in the Ada language of any kind of dynamic loading. > (Which is > not to say that Ada can't use dynamic linking on those operating systems > that have it, only that it's not part of the standard language or > libraries > in the same way that it's not part of the standard C language or > libraries.) > OK, I see. I never paid too much attention to these issues since neither make a whole lot of difference for my current projects (or, I've never programmed in a language that allows "hot loading", so maybe I have no idea what I've been missing). > Interestingly, both Ada 95 and Erlang/OTP allow a kind of dotted > module name, > and from my point of view they both got the dotted names inside out, > but Ada > 95 "child packages" really have some point to them. (For example an Ada > package can have *private* children that other packages cannot see. > Neither > Java nor Erlang can manage that. Also, Ada children can be allowed > to see > inside their parents, which again neither Java nor its slavish > imitator in > this respect, Erlang, allows.) > > Arguably the single most important difference between Ada and Erlang is > that Ada is an imperative language relying on destructive updates to > variables and arrays, while Erlang is mostly functional. One of the Yes, this part I was aware of. I understand it is a big difference but I guess that this ought not to stop anyone from using Erlang or Ada if either one meets their needs. > things > that makes Ada a nice language for concurrency is that it doesn't SHARE > mutable data between tasks. But you cannot run into trouble in this issue with Erlang, either. The nearest it comes is something called a > 'protected record', which is essentially a 'monitor' (or a Java > object all > of whose methods are synchronised and with no exported fields). > Nevertheless > it is only really at home on shared *memory* machines. > Aha, that is something I wasn't aware of. And that seems a crucial point. > Ada doesn't have any form of pattern matching other than a 'case' > statement Yep. Erlang's pattern matching is a very neat feature. > which is similar to (but MUCH cleaner and far easier to get right) the > C/C++/Java 'switch' statement. It _could_ have something fancier; > Mesa did. > > Thanks again for your detailed answers. Best, R. > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- Ramon Diaz-Uriarte Statistical Computing Team Structural Biology and Biocomputing Programme Spanish National Cancer Centre (CNIO) http://ligarto.org/rdiaz From bob@REDACTED Sun Apr 1 19:28:37 2007 From: bob@REDACTED (Bob Ippolito) Date: Sun, 1 Apr 2007 10:28:37 -0700 Subject: [erlang-questions] Start module In-Reply-To: References: Message-ID: <6a36e7290704011028q4c237f08i6784f55436163c99@mail.gmail.com> On 4/1/07, Fredrik Hoback wrote: > Hi, I have a project that I'm working on which consists of several modules. > These has to be loaded ( l(my_module). ) and started in a special order. > Since I have 5 modules it is cumbersome to do this every time. Is it > possible to construct a new module that does this? It should first load some > modules then start them? > Modules are loaded automatically when a function is called in them. You shouldn't need to explicitly load the module unless you're trying to replace the current version with a new beam file. It sounds like what you want to do is write a supervisor... -bob From lennart.ohman@REDACTED Sun Apr 1 19:33:17 2007 From: lennart.ohman@REDACTED (Lennart Ohman) Date: Sun, 1 Apr 2007 19:33:17 +0200 Subject: [erlang-questions] Start module In-Reply-To: References: Message-ID: <000c01c77483$d576a9d0$0300a8c0@st.se> Hi Fredrik, I am not sure if I now answer something in the middle of a thread, but unless you have done something to your Erlang system, modules are automatically loaded on demand. The l/1 shell function you are referring to is only necessary if you want to reload the module (like after you have a bew better version available). If reloading modules in runtime *is* what you want to do and you want it to be done in som "automagic" way, you need to look at the API of 'code'. What you will be doing in that case is actually building a kind of release handler, and requires understanding of the new/old code concepts. Best Regards Lennart ------------------------------------------------------------- Lennart Ohman office : +46-8-587 623 27 Sjoland & Thyselius Telecom AB cellular: +46-70-552 67 35 H?lsingegatan 43, 10tr fax : +46-8-667 82 30 SE-113 31, STOCKHOLM, SWEDEN email : lennart.ohman@REDACTED > -----Original Message----- > From: erlang-questions-bounces@REDACTED [mailto:erlang-questions- > bounces@REDACTED] On Behalf Of Fredrik Hoback > Sent: Sunday, April 01, 2007 11:21 AM > To: erlang-questions@REDACTED > Subject: [erlang-questions] Start module > > Hi, I have a project that I'm working on which consists of several > modules. These has to be loaded ( l(my_module). ) and started in a special > order. Since I have 5 modules it is cumbersome to do this every time. Is > it possible to construct a new module that does this? It should first load > some modules then start them? > ------------------------------------ > Fredrik Hoback > fredrik.hoback@REDACTED > > From atencorps@REDACTED Sun Apr 1 21:24:43 2007 From: atencorps@REDACTED (adfafd adfadfafddafa) Date: Sun, 01 Apr 2007 14:24:43 -0500 Subject: [erlang-questions] Freelancers Message-ID: <20070401192443.2E7F21F514D@ws1-2.us4.outblaze.com> Hi all Im after an Erlang programmer who is willing to work on a job for me . Whether they charge per hour or per job is fine. I already have a program in Erlang and require the program to be improved and also a windows client made for it . Having searched in sites like Elance,SL , Rentacoder etc I thought I would post a request here. Alternatively if anyone knows of sites where I may find Erlang freelancers then please let me know Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeffm@REDACTED Mon Apr 2 00:54:45 2007 From: jeffm@REDACTED (jm) Date: Mon, 02 Apr 2007 08:54:45 +1000 Subject: [erlang-questions] Erlang and Ada (and now Hume) In-Reply-To: <624934630704010943p71a225e2jaf66cd1830973f62@mail.gmail.com> References: <624934630703290300v7e489ee2tad98c065e523f861@mail.gmail.com> <624934630704010943p71a225e2jaf66cd1830973f62@mail.gmail.com> Message-ID: <46103835.8020709@ghostgun.com> Following this thread made me wonder if there was a functional programming language suitable for hard real-time applications, the sort of thing that Ada is normally used for, and, if not, why not. Searching for "hard realtime functional programming language" I came across this paper http://homepages.inf.ed.ac.uk/stg/workshops/TFP/book/Hammond/TFP03-Hammond/tfp03.pdf In which it lists the "Essential properties of real-time languages" as determinacy, bounded time/space, asynchronicity, concurrency, correctness, and adds periodic scheduling, and interrupts and polling. They go on to discuss the different approaches taken in designing real-time languages, either by adapting an existing general language or by creating a domain specific language. Ada, SPARK Ada, Java, Erlang, and a few less well known languages get mentioned. Before turning their attention to why function language haven't seen much application in this space before (mostly due to bounding space/time). Finally, they turn to there own language Hume (http://www.hume-lang.org/). Having only heard of this language in passing before I was wondering what anyone out there knew and thought about it. There seems to be a few examples on the website to do with hard real-time application, but as yet I haven't had the time to look at the language in any detail. Anyone had some experience with Hume? Jeff. From bob@REDACTED Mon Apr 2 03:44:24 2007 From: bob@REDACTED (Bob Ippolito) Date: Sun, 1 Apr 2007 18:44:24 -0700 Subject: [erlang-questions] R11B-3 shell crashes when printing float infinity Message-ID: <6a36e7290704011844w6d2c2e8bo1b19ccb66e44140c@mail.gmail.com> I haven't installed R11B-4 on my workstation yet, so I'm not sure if this is still applicable... but I just noticed that the R11B-3 shell crashes if you try and get it to print out float infinity. Erlang (BEAM) emulator version 5.5.3 [source] [async-threads:0] [kernel-poll:false] Eshell V5.5.3 (abort with ^G) 1> float_to_list(1.0e666666). "inf" 2> 1.0e666666. *** ERROR: Shell process terminated! (^G to start new job) *** =ERROR REPORT==== 1-Apr-2007::18:41:54 === Error in process <0.23.0> with exit value: {function_clause,[{io_lib_format,float_data,[[],[]]},{io_lib_format,fwrite_e,5},{shell,shell_rep,4},{shell,server_loop,7}]} -bob From ok@REDACTED Mon Apr 2 05:19:31 2007 From: ok@REDACTED (ok) Date: Mon, 2 Apr 2007 15:19:31 +1200 Subject: [erlang-questions] Erlang and Ada In-Reply-To: <624934630704010943p71a225e2jaf66cd1830973f62@mail.gmail.com> References: <624934630703290300v7e489ee2tad98c065e523f861@mail.gmail.com> <624934630704010943p71a225e2jaf66cd1830973f62@mail.gmail.com> Message-ID: I wrote: >> However, I can certainly assure you that there is nothing in any >> of the >> previous Ada standards concerning distribution. Ada was designed >> to be This was far too strong, and I was hoping to fix this up before anyone noticed. However, On 2 Apr 2007, at 4:43 am, Ramon Diaz-Uriarte wrote: > > Aha, I see. You obviously know this stuff, so I won't argue, but I > thought in Appendix E (for Ada 95) there was some stuff related > to/relevant for distribution. It's "Annex" E, and its title is "Distributed Systems". I had made a serious mistake. Annexes K to P "are for information only"; my mistake was thinking that Annex E was one of the "informative" annexes. In fact Annex is is "Normative", and "Annexes A to J form an integral part of this international standard", so distribution *IS* "an integral part of" Ada 95. (It made sense for distribution to be optional, given that many of the systems on which one would want to use Ada couldn't make use of distribution facilities. But that's not the way the real world is.) One is left wondering why "integral parts" are split off as "annexes" rather than "chapters". However, annexes C to H are the "Specialized Needs" annexes, which again strongly suggests to the feeble-minded reader (ME) that they are not required of all systems. Chapter 10, which says An implementation may provide inter-partition communication mechanism(s) via special packages and pragmas. ... If no such mechanisms are provided, then each partition is isolated from all others, and behaves as a program in and of itself. does not encourage the reader to believe that distribution facilities can be relied on to be present. What is quite clear is that Annex E itself says that The implementation shall provide means for explicitly assigning library units to a partition and for the configuring and execution of a program consisting of multiple partitions on a distributed system; THE MEANS ARE IMPLEMENTATION-DEFINED. That is, there is no *standard* way to say what the distribution of an Ada program actually *is* nor to cause a distributed Ada program to run. ... the scheduling policies, treatment of priorities, and management of shared resources between [...] partitions [that are mapped onto the same node] are IMPLEMENTATION-DEFINED. Ada 95 distribution does not handle update, but does provide 'Version and 'Body_Version attributes that you can use to detect when update would hhave been necessary. These things change whenever there is a semantically significant change, EXCEPT that This International Standard does not define ... "semantically significant". Let me characterise Ada 95 distribution this way: Ada 95 provides language means for specifying a program that *MAY* be distributed, but not means for specifying that it *MUST* be distributed, nor any way for saying *HOW* it is distributed. The summary of the summary is There is a reliable way for an Erlang program to say "I want to run over ." There is no portable way for an Ada program to do that. And from my point of view, that amounts to saying that there is nothing in Ada 95 that I can recognise as useful distribution. (Not to mention the fact that an Ada 95 implementation is only required to make distribution work between identical machines.) > > OK, I see. I never paid too much attention to these issues since > neither make a whole lot of difference for my current projects (or, > I've never programmed in a language that allows "hot loading", so > maybe I have no idea what I've been missing). Lisp, Smalltalk, Prolog, TCL, Python (I think). We are even seeing C systems with "fix and continue" in the debugger (not that I trust them...) From bengt.kleberg@REDACTED Mon Apr 2 08:49:24 2007 From: bengt.kleberg@REDACTED (Bengt Kleberg) Date: Mon, 02 Apr 2007 08:49:24 +0200 Subject: [erlang-questions] OT Re: Erlang and Ada In-Reply-To: References: <624934630703290300v7e489ee2tad98c065e523f861@mail.gmail.com> <624934630704010943p71a225e2jaf66cd1830973f62@mail.gmail.com> Message-ID: <4610A774.7060108@ericsson.com> On 2007-04-02 05:19, ok wrote: ...deleted > Lisp, Smalltalk, Prolog, TCL, Python (I think). We are even seeing > C systems with "fix and continue" in the debugger (not that I trust > them...) about 20 years ago i was building a real time expert system for the oil industry in noreway. we had a UniWorks system (vxWorks+Unix) where the c debugger contained the command ffb. according to the documentation it was for ''find and fix bug''. not that i ever needed to use it :-) bengt -- Those were the days... EPO guidelines 1978: "If the contribution to the known art resides solely in a computer program then the subject matter is not patentable in whatever manner it may be presented in the claims." From mikpe@REDACTED Mon Apr 2 09:00:07 2007 From: mikpe@REDACTED (Mikael Pettersson) Date: Mon, 2 Apr 2007 09:00:07 +0200 (MEST) Subject: [erlang-questions] R11B-3 shell crashes when printing float infinity Message-ID: <200704020700.l32707Xv004549@harpo.it.uu.se> On Sun, 1 Apr 2007 18:44:24 -0700, Bob Ippolito wrote: > I haven't installed R11B-4 on my workstation yet, so I'm not sure if > this is still applicable... but I just noticed that the R11B-3 shell > crashes if you try and get it to print out float infinity. > > Erlang (BEAM) emulator version 5.5.3 [source] [async-threads:0] > [kernel-poll:false] > > Eshell V5.5.3 (abort with ^G) > 1> float_to_list(1.0e666666). > "inf" > 2> 1.0e666666. > *** ERROR: Shell process terminated! (^G to start new job) *** > > =ERROR REPORT==== 1-Apr-2007::18:41:54 === > Error in process <0.23.0> with exit value: > {function_clause,[{io_lib_format,float_data,[[],[]]},{io_lib_format,fwrite_e,5},{shell,shell_rep,4},{shell,server_loop,7}]} Your system is broken. Erlang doesn't allow infinities or NaNs. In a working system, the expression "1.0e666666" is supposed to be rejected by the parser (and it is in my system). Please try R11B-4 first. If the invalid float constant still is accepted, file a bug report. Useful information would be which CPU, OS and C compiler you're using, and whether ./configure identified "reliable floating-point exceptions" or not. /Mikael From surindar.shanthi@REDACTED Mon Apr 2 09:31:12 2007 From: surindar.shanthi@REDACTED (Surindar Sivanesan) Date: Mon, 2 Apr 2007 13:01:12 +0530 Subject: [erlang-questions] Error while writing to a file In-Reply-To: <42ea5fb60703220812o26faff95gc39ea9c3d78fddda@mail.gmail.com> References: <42ea5fb60703220812o26faff95gc39ea9c3d78fddda@mail.gmail.com> Message-ID: <42ea5fb60704020031s683b900mc7fa8c1223dec2b5@mail.gmail.com> Dear all, Its a gentle reminder. Sorry for disturbing you all again. Since this error in writing file is happening often, please give your inputs. On 3/22/07, Surindar Sivanesan wrote: > > Dear all, > I have an application in Erlang which has as many as 200 processes running > simultaneously. > All the 200 process will access a process (Module name -file_writer) which > write log to a file. Sometimes, the following error is occured. > > =ERROR REPORT==== 22-Mar-2007::15:45:16 === > ** Generic server file_writer terminating > ** Last message in was {'$gen_cast',{write_log, > "22/3/2007", > "15:45:16", > "Empty", > "Process_63", > "Process 63 log off"}} > ** When Server state == [<0.45.0>,<0.44.0>] > ** Reason for termination == > ** {badarg,[{io,put_chars,[<0.45.0>,"22/3/2007"]}, > {io,o_request,2}, > {file_writer,handle_cast,2}, > {gen_server,handle_msg,6}, > {proc_lib,init_p,5}]} > > Please help me in sorting out this problem. > > -- > with regards, > S.Surindar > -- with regards, S.Surindar -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob@REDACTED Mon Apr 2 09:31:20 2007 From: bob@REDACTED (Bob Ippolito) Date: Mon, 2 Apr 2007 00:31:20 -0700 Subject: [erlang-questions] R11B-3 shell crashes when printing float infinity In-Reply-To: <200704020700.l32707Xv004549@harpo.it.uu.se> References: <200704020700.l32707Xv004549@harpo.it.uu.se> Message-ID: <6a36e7290704020031x853f297o9e1c70c5e9f39c4e@mail.gmail.com> On 4/2/07, Mikael Pettersson wrote: > On Sun, 1 Apr 2007 18:44:24 -0700, Bob Ippolito wrote: > > I haven't installed R11B-4 on my workstation yet, so I'm not sure if > > this is still applicable... but I just noticed that the R11B-3 shell > > crashes if you try and get it to print out float infinity. > > > > Erlang (BEAM) emulator version 5.5.3 [source] [async-threads:0] > > [kernel-poll:false] > > > > Eshell V5.5.3 (abort with ^G) > > 1> float_to_list(1.0e666666). > > "inf" > > 2> 1.0e666666. > > *** ERROR: Shell process terminated! (^G to start new job) *** > > > > =ERROR REPORT==== 1-Apr-2007::18:41:54 === > > Error in process <0.23.0> with exit value: > > {function_clause,[{io_lib_format,float_data,[[],[]]},{io_lib_format,fwrite_e,5},{shell,shell_rep,4},{shell,server_loop,7}]} > > Your system is broken. Erlang doesn't allow infinities or NaNs. > In a working system, the expression "1.0e666666" is supposed to > be rejected by the parser (and it is in my system). It's nothing I'm running into with production code, but I was writing a JSON encoder/decoder and happened to type in a float that was out of range and the shell exploded on me. > Please try R11B-4 first. If the invalid float constant still > is accepted, file a bug report. Useful information would be > which CPU, OS and C compiler you're using, and whether ./configure > identified "reliable floating-point exceptions" or not. > I don't have time to compile and test with R11B-4 for at least a few days, but I can produce this bug with FreeBSD 6.2 x86-32 with R11B-3 compiled from ports, and also on Mac OS X 10.4.9 x86-32 with R11B-3 compiled without any special flags "./configure && make && sudo make install". >From where I'm sitting, it looks like this is simply a bug that is most likely fixed in R11B-4. -bob From bengt.kleberg@REDACTED Mon Apr 2 10:24:35 2007 From: bengt.kleberg@REDACTED (Bengt Kleberg) Date: Mon, 02 Apr 2007 10:24:35 +0200 Subject: [erlang-questions] Escript In-Reply-To: References: <20070328234531.359557d0.mle+erlang@mega-nerd.com> <460D10CB.2010608@ericsson.com> Message-ID: <4610BDC3.9090200@ericsson.com> On 2007-03-30 18:24, Julian Fondren wrote: > On 3/30/07, Bengt Kleberg wrote: >> it it possible to get the name of the script when using escript? > > escript throws it away: > > start([_|X]) -> > X0 = map(fun(I) -> binary_to_list(I) end, X), > [_,File|Args] = X0, > ___, 1 this is not the escript in R11B-4, but yes the file name is removed from the arguments in R11B-4, too. that was why i wanted to get hold of it some other way. 2 the answer is: use init:get_plain_arguments(). like this: #! /tmp/erlang/bin/escript main(_) -> [Script_name|_T] = init:get_plain_arguments(), io:fwrite("~s~n", [Script_name]). i would have prefered to have the script as the first argument (like in my patches) but this works. bengt -- Those were the days... EPO guidelines 1978: "If the contribution to the known art resides solely in a computer program then the subject matter is not patentable in whatever manner it may be presented in the claims." From rdiaz02@REDACTED Mon Apr 2 11:45:42 2007 From: rdiaz02@REDACTED (Ramon Diaz-Uriarte) Date: Mon, 2 Apr 2007 11:45:42 +0200 Subject: [erlang-questions] Erlang and Ada In-Reply-To: References: <624934630703290300v7e489ee2tad98c065e523f861@mail.gmail.com> <624934630704010943p71a225e2jaf66cd1830973f62@mail.gmail.com> Message-ID: <624934630704020245h5b06138aie25d9af24fea97bc@mail.gmail.com> On 4/2/07, ok wrote: > I wrote: > >> However, I can certainly assure you that there is nothing in any > >> of the > >> previous Ada standards concerning distribution. Ada was designed > >> to be > > This was far too strong, and I was hoping to fix this up before anyone > noticed. However, > On 2 Apr 2007, at 4:43 am, Ramon Diaz-Uriarte wrote: > > > > > Aha, I see. You obviously know this stuff, so I won't argue, but I > > thought in Appendix E (for Ada 95) there was some stuff related > > to/relevant for distribution. > > It's "Annex" E, and its title is "Distributed Systems". > I had made a serious mistake. Annexes K to P "are for information > only"; > my mistake was thinking that Annex E was one of the "informative" > annexes. > In fact Annex is is "Normative", and "Annexes A to J form an integral > part > of this international standard", so distribution *IS* "an integral > part of" > Ada 95. (It made sense for distribution to be optional, given that many > of the systems on which one would want to use Ada couldn't make use of > distribution facilities. But that's not the way the real world is.) > > One is left wondering why "integral parts" are split off as "annexes" > rather than "chapters". However, annexes C to H are the "Specialized > Needs" annexes, which again strongly suggests to the feeble-minded > reader > (ME) that they are not required of all systems. Chapter 10, which says > An implementation may provide inter-partition communication > mechanism(s) via special packages and pragmas. ... If no such > mechanisms are provided, then each partition is isolated from > all others, and behaves as a program in and of itself. > does not encourage the reader to believe that distribution facilities > can > be relied on to be present. > > What is quite clear is that Annex E itself says that > The implementation shall provide means for explicitly assigning > library units to a partition and for the configuring and > execution of a program consisting of multiple partitions on a > distributed system; THE MEANS ARE IMPLEMENTATION-DEFINED. > > That is, there is no *standard* way to say what the distribution of an > Ada program actually *is* nor to cause a distributed Ada program to run. > > ... the scheduling policies, treatment of priorities, and > management of shared resources between [...] partitions [that > are mapped onto the same node] are IMPLEMENTATION-DEFINED. > > Ada 95 distribution does not handle update, but does provide 'Version > and > 'Body_Version attributes that you can use to detect when update would > hhave > been necessary. These things change whenever there is a semantically > significant change, EXCEPT that > > This International Standard does not define ... "semantically > significant". > > Let me characterise Ada 95 distribution this way: > > Ada 95 provides language means for specifying a program that *MAY* > be distributed, but not means for specifying that it *MUST* be > distributed, nor any way for saying *HOW* it is distributed. > > The summary of the summary is > > There is a reliable way for an Erlang program to say "I want to run > over ." There is no portable way for an Ada program > to do that. > > And from my point of view, that amounts to saying that there is > nothing in > Ada 95 that I can recognise as useful distribution. (Not to mention the > fact that an Ada 95 implementation is only required to make distribution > work between identical machines.) > > Thanks _a lot_ for the detailed and exhaustive search into the issue and for your answer. Now I think I understand the issue and what it really means when it says Ada allows for distributed computing. (This still leaves open the question of why its so hard to find statements like this in other places. I mean, comparisons of Ada and Erlang in the realm of concurrency and distributed computing. But that is a completely different question). > > > OK, I see. I never paid too much attention to these issues since > > neither make a whole lot of difference for my current projects (or, > > I've never programmed in a language that allows "hot loading", so > > maybe I have no idea what I've been missing). > > Lisp, Smalltalk, Prolog, TCL, Python (I think). We are even seeing > C systems with "fix and continue" in the debugger (not that I trust > them...) > Ooops, I've used Scheme a little bit and Python quite a bit. I think its time for me to go and learn what the things I use can really do before talking :-). Thanks again for your clarifications. Best, R. > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- Ramon Diaz-Uriarte Statistical Computing Team Structural Biology and Biocomputing Programme Spanish National Cancer Centre (CNIO) http://ligarto.org/rdiaz From bjorn@REDACTED Mon Apr 2 11:48:43 2007 From: bjorn@REDACTED (Bjorn Gustavsson) Date: 02 Apr 2007 11:48:43 +0200 Subject: [erlang-questions] Escript In-Reply-To: <460D10CB.2010608@ericsson.com> References: <20070328234531.359557d0.mle+erlang@mega-nerd.com> <460D10CB.2010608@ericsson.com> Message-ID: I based the R11B-4 version of escript on Joe's escript-4.1 (without your patch), but among other things I changed how the arguments are passed. I did consider passing the script name as the first argument in the list, but in the end I didn't want to break compatibility with Joe's escript or with the description in his book. We'll probably add a function to the escript module to retrieve the name of the script in the R11B-5 release. (Unless someone comes up with a better name, I'll probably call it escript:script_name/0.) /Bjorn Bengt Kleberg writes: > On 2007-03-28 15:52, Bjorn Gustavsson wrote: > > escript is included in R11B-4. > > it it possible to get the name of the script when using escript? > > i notice that the escript that is included in R11B-4 does not have the > script itself as the first argument (like a $0 is a shell script). ex: > #! /tmp/erlang/bin/escript > > main( Arg ) -> > io:fwrite( "~w~n", [Arg] ). > > > i made a patch for joe's escript-4.1 that made the script name > available, but escript.erl in R11B-4 does not look like it was made from > escript-4.1 > > > bengt > -- > Those were the days... > EPO guidelines 1978: "If the contribution to the known art resides > solely in a computer program then the subject matter is not > patentable in whatever manner it may be presented in the claims." > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- Bj?rn Gustavsson, Erlang/OTP, Ericsson AB From serge@REDACTED Mon Apr 2 21:39:34 2007 From: serge@REDACTED (Serge Aleynikov) Date: Mon, 02 Apr 2007 15:39:34 -0400 Subject: [erlang-questions] run_erl.c question in R11B-4 Message-ID: <46115BF6.5020606@hq.idt.net> Hi, I see that a SIGCHLD handler was added in run_erl.c in the R11B-4. However the implementation of the signal handler function (catch_sigchild) has nothing in the body. I believe it should be: --- ./erts/etc/unix/run_erl.c.orig 2006-11-22 10:57:35.000000000 -0500 +++ ./erts/etc/unix/run_erl.c 2007-04-02 15:23:45.000000000 -0400 @@ -676,6 +676,10 @@ static void catch_sigchild(int sig) { + int stat; + status("Child terminated - exiting\n"); + wait(&stat); /* Ensure that a child entry in the process table is cleared, and release child's PID */ + exit(2); } This way the death of the emulator will cause the death of run_erl. Otherwise in presence of the -heart option it's possible to get in a situation when run_erl is not properly restarted (*). Serge (*) http://www.erlang.org/ml-archive/erlang-questions/200601/msg00473.html -- Serge Aleynikov Routing R&D, IDT Telecom Tel: +1 (973) 438-3436 Fax: +1 (973) 438-1464 From per@REDACTED Mon Apr 2 23:15:28 2007 From: per@REDACTED (Per Hedeland) Date: Mon, 2 Apr 2007 23:15:28 +0200 (CEST) Subject: [erlang-questions] R11B-3 shell crashes when printing float infinity In-Reply-To: <6a36e7290704020031x853f297o9e1c70c5e9f39c4e@mail.gmail.com> Message-ID: <200704022115.l32LFS1G031063@pluto.hedeland.org> "Bob Ippolito" wrote: > >On 4/2/07, Mikael Pettersson wrote: >> On Sun, 1 Apr 2007 18:44:24 -0700, Bob Ippolito wrote: >> > I haven't installed R11B-4 on my workstation yet, so I'm not sure if >> > this is still applicable... but I just noticed that the R11B-3 shell >> > crashes if you try and get it to print out float infinity. >> > >> > Erlang (BEAM) emulator version 5.5.3 [source] [async-threads:0] >> > [kernel-poll:false] >> > >> > Eshell V5.5.3 (abort with ^G) >> > 1> float_to_list(1.0e666666). >> > "inf" >> > 2> 1.0e666666. >> > *** ERROR: Shell process terminated! (^G to start new job) *** >> > >> > =ERROR REPORT==== 1-Apr-2007::18:41:54 === >> > Error in process <0.23.0> with exit value: >> > {function_clause,[{io_lib_format,float_data,[[],[]]},{io_lib_format,fwrite_e,5},{shell,shell_rep,4},{shell,server_loop,7}]} >> >> Your system is broken. Erlang doesn't allow infinities or NaNs. >> In a working system, the expression "1.0e666666" is supposed to >> be rejected by the parser (and it is in my system). > >It's nothing I'm running into with production code, but I was writing >a JSON encoder/decoder and happened to type in a float that was out of >range and the shell exploded on me. > >> Please try R11B-4 first. If the invalid float constant still >> is accepted, file a bug report. Useful information would be >> which CPU, OS and C compiler you're using, and whether ./configure >> identified "reliable floating-point exceptions" or not. >> > >I don't have time to compile and test with R11B-4 for at least a few >days, but I can produce this bug with FreeBSD 6.2 x86-32 with R11B-3 >compiled from ports, and also on Mac OS X 10.4.9 x86-32 with R11B-3 >compiled without any special flags "./configure && make && sudo make >install". Ditto with R11B-3 on Linux FC5 2.6.17-1.2174_FC5, i686, gcc 4.1.1 20060525. From ./configure: checking for unreliable floating point execptions... reliable (yup, it says "execptions":-). --Per Hedeland From bjorn@REDACTED Tue Apr 3 11:31:43 2007 From: bjorn@REDACTED (Bjorn Gustavsson) Date: 03 Apr 2007 11:31:43 +0200 Subject: [erlang-questions] benefits of binary format strings? In-Reply-To: <200704010043.11752.als@iinet.net.au> References: <200704010043.11752.als@iinet.net.au> Message-ID: Yes, there is a slight performance benefit, as the format string will be sent in a message to another process. /Bjorn Anthony Shipman writes: > The new R11B-4 has this change: > > OTP-6517 The Format argument of the functions io:fwrite/2,3 and > io_lib:fwrite/2 is now allowed to be a binary. > > Are there performance benefits from writing io:format(<<"hello world~n">>, []) > compared with a bare string? > > -- > Anthony Shipman Mamas don't let your babies > als@REDACTED grow up to be outsourced. > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- Bj?rn Gustavsson, Erlang/OTP, Ericsson AB From posttopublicity@REDACTED Tue Apr 3 11:55:10 2007 From: posttopublicity@REDACTED (E. Segura) Date: Tue, 3 Apr 2007 02:55:10 -0700 Subject: [erlang-questions] CFP - 2nd IEEE International Workshop Towards Stable and Adaptable Software Architectures (SASA 2007) Message-ID: <601f368dcc66ae2285f25de5495f6f03@ijop.org> The 2nd IEEE International Workshop Towards Stable and Adaptable Software Architectures SASA 2007 Invitation Las Vegas, USA, August 13-15, 2007 (in conjunction with IEEE IRI 2007) http://www.sis.pitt.edu/~iri07/ (IEEE IRI 2007 Link) http://www.sis.pitt.edu/~iri07/wkshpCFP2.html (Workshop Link 1) http://www.engr.sjsu.edu/~fayad/workshops/SASA07 (Workshop Link 2) http://www.vrlsoft.com/workshops/SASA07 (Workshop Link 3) Greetings, I would like to invite you to participate in The 2nd IEEE International Workshop Towards Stable and Adaptable Software Architectures (SASA 2007)" In conjunction with The 2007 IEEE International Conference on Information Reuse and Integration (http://www.sis.pitt.edu/~iri07/), which will take place in Las Vegas, Nevada, August 13-15, 2OO7 by submitting a paper or two before or on April 15, 2007. A call of papers for the workshop is enclosed and it can be found at: http://www.sis.pitt.edu/~iri07/wkshpCFP2.html (Workshop Link 1) http://www.engr.sjsu.edu/~fayad/workshops/SASA07 (Workshop Link 2) http://www.vrlsoft.com/workshops/SASA07 (Workshop Link 3) Accepted papers will be published in the proceedings (EI Index) of the The 2007 IEEE International Conference on Information Reuse and Integration (IEEE IRI 2007). The workshop selected best papers will be published in online Journal of International Journal Of Patterns (IJOP). Looking forward to your submission and participation in the workshop! All the best, Cheers, Dr. M.E. Fayad (Chair) Dr. Rami Bahsoon (Co-Chair) Dr. Tarek Helmy (Co-Chair) Eduardo M. Segura (Co-Chair) -- ijop.org -- Powered by PHPlist, www.phplist.com -- From posttopublicity@REDACTED Tue Apr 3 12:52:22 2007 From: posttopublicity@REDACTED (E.Segura) Date: Tue, 3 Apr 2007 03:52:22 -0700 Subject: [erlang-questions] 2nd IEEE International Workshop on Software Stability at Work (SSW 2007) Message-ID: The 2nd IEEE International Workshop on Software Stability at Work SSW 2007 Invitation Las Vegas, USA, August 13-15, 2007 (in conjunction with IEEE IRI 2007) http://www.sis.pitt.edu/~iri07/ (IEEE IRI 2007 Link) http://www.sis.pitt.edu/~iri07/wkshpCFP3.html (Main Link) http://www.engr.sjsu.edu/~fayad/workshops/IRI07-SSW (Workshop Link 2) http://www.vrlsoft.com/workshops/SSW07 (Workshop Link 3) Greetings, I would like to invite you to participate in The 2nd IEEE International Workshop on Software Stability at Work. (SSW 2007)" In conjunction with The 2007 IEEE International Conference on Information Reuse and Integration (http://www.sis.pitt.edu/~iri07/), which will take place in Las Vegas, Nevada, August 13-15, 2OO7 by submitting a paper or two before or on April 15, 2007. A call of papers for the workshop is enclosed and it can be found at: http://www.sis.pitt.edu/~iri07/wkshpCFP3.html (Main Link) http://www.engr.sjsu.edu/~fayad/workshops/IRI07-SSW (Workshop Link 2) http://www.vrlsoft.com/workshops/SSW07 (Workshop Link 3) Accepted papers will be published in the proceedings (EI Index) of the The 2007 IEEE International Conference on Information Reuse and Integration (IEEE IRI 2007). The workshop selected best papers will be published in online Journal of International Journal Of Patterns (IJOP). Looking forward to your submission and participation in the workshop! All the best, Cheers, Dr. M.E. Fayad (Chair) Dr. Rami Bahsoon (Co-Chair) Dr. Chia-Chu Chiang (Co-Chair) Dr. Shasha Wu (Co-Chair) -- ijop.org -- Powered by PHPlist, www.phplist.com -- From erlang@REDACTED Tue Apr 3 17:11:58 2007 From: erlang@REDACTED (Peter Lund) Date: Tue, 03 Apr 2007 17:11:58 +0200 Subject: [erlang-questions] "-noshell" on R9C Message-ID: <46126EBE.105@lundata.se> Trying to use io:print_chars/1 on R9C in combination with unix pipes and the "-noshell" option on a new MacOS X machine. Does anyone perhaps know why I get "[]" before each character below? $ erlc myprint.erl $ cat test.txt My example text. $ cat test.txt | erl -noshell -run myprint print []M[]y[] []e[]x[]a[]m[]p[]l[]e[] []t[]e[]x[]t[].[] []Num chars 17 $ cat myprint.erl -module(myprint). -export([print/0]). print() -> print(get_char(),0). print(eof,N) -> io:format("Num chars ~p\n",[N]), halt(); print(C,N) when is_integer(C) -> io:put_chars([C]), print(get_char(),N+1). get_char() -> case io:get_chars("",1) of eof -> eof; [C] -> C end. $ From oscar@REDACTED Tue Apr 3 17:31:09 2007 From: oscar@REDACTED (Oscar =?ISO-8859-1?B?SGVsbHN0cvZt?=) Date: Tue, 3 Apr 2007 16:31:09 +0100 Subject: [erlang-questions] "-noshell" on R9C In-Reply-To: <46126EBE.105@lundata.se> References: <46126EBE.105@lundata.se> Message-ID: <20070403163109.10d172a4@linux.site> On Tue, 03 Apr 2007 17:11:58 +0200 Peter Lund wrote: > Trying to use io:print_chars/1 on R9C in combination with unix pipesand > the "-noshell" option on a new MacOS X machine. > > Does anyone perhaps know why I get "[]" before each character below? The [] are actually part of your prompt. "" is the same thing as an empty list, try to use the '' atom instead. > $ erlc myprint.erl > > $ cat test.txt > My example text. > > $ cat test.txt | erl -noshell -run myprint print > []M[]y[] []e[]x[]a[]m[]p[]l[]e[] []t[]e[]x[]t[].[] > []Num chars 17 > > $ cat myprint.erl > -module(myprint). > > -export([print/0]). > > print() -> print(get_char(),0). > > print(eof,N) -> > io:format("Num chars ~p\n",[N]), > halt(); > print(C,N) when is_integer(C) -> > io:put_chars([C]), > print(get_char(),N+1). > > get_char() -> > case io:get_chars("",1) of > eof -> eof; > [C] -> C > end. > $ > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions -- Oscar Hellstr?m, oscar@REDACTED Erlang Training and Consulting From javierparis@REDACTED Tue Apr 3 17:49:45 2007 From: javierparis@REDACTED (Javier =?iso-8859-1?q?Par=EDs?=) Date: Tue, 3 Apr 2007 17:49:45 +0200 Subject: [erlang-questions] sendfile and statfs Message-ID: <200704031749.46316.javierparis@udc.es> Hi, I have been searching the documentation looking for functions that map the sendfile and statfs syscalls, but I have not found any. I remember seeing (a long time ago :) ) a patch that added sendfile support, but I suppose it has not been included. Have I overlooked them? Is there any plans to add them? Having to code a C Port just for this makes me feel dirty :). Regards. -- Javier Par?s From als@REDACTED Tue Apr 3 19:01:16 2007 From: als@REDACTED (Anthony Shipman) Date: Wed, 4 Apr 2007 04:01:16 +1100 Subject: [erlang-questions] spawn race condition? Message-ID: <200704040301.16065.als@iinet.net.au> I have code that looks like this: call(Phone) -> Pid = spawn(?MODULE, init, [Phone]), util:delay(100), Pid! {startCall, self()}, receive callComplete -> {ok, Pid} after 5000 -> false end. If I don't have the 100ms delay then the only message that the new process receives is the integer 0. It works with the delay. Am I missing something? -- Anthony Shipman Mamas don't let your babies als@REDACTED grow up to be outsourced. From erlang@REDACTED Tue Apr 3 19:02:21 2007 From: erlang@REDACTED (Peter Lund) Date: Tue, 03 Apr 2007 19:02:21 +0200 Subject: [erlang-questions] "-noshell" on R9C In-Reply-To: <20070403163109.10d172a4@linux.site> References: <46126EBE.105@lundata.se> <20070403163109.10d172a4@linux.site> Message-ID: <4612889D.2040507@lundata.se> Yes, that was it!! It works better with io:get_chars('',1). or with file:read(group_leader(),1). I guess that it would be good if OTP added a io:get_chars/1 where only the number of chars are specified to make the API simplier to use. :) /Peter Oscar Hellstr?m skrev: > On Tue, 03 Apr 2007 17:11:58 +0200 > Peter Lund wrote: > > >> Trying to use io:print_chars/1 on R9C in combination with unix pipesand >> the "-noshell" option on a new MacOS X machine. >> >> Does anyone perhaps know why I get "[]" before each character below? >> > > The [] are actually part of your prompt. "" is the same thing as an > empty list, try to use the '' atom instead. > > >> $ erlc myprint.erl >> >> $ cat test.txt >> My example text. >> >> $ cat test.txt | erl -noshell -run myprint print >> []M[]y[] []e[]x[]a[]m[]p[]l[]e[] []t[]e[]x[]t[].[] >> []Num chars 17 >> >> $ cat myprint.erl >> -module(myprint). >> >> -export([print/0]). >> >> print() -> print(get_char(),0). >> >> print(eof,N) -> >> io:format("Num chars ~p\n",[N]), >> halt(); >> print(C,N) when is_integer(C) -> >> io:put_chars([C]), >> print(get_char(),N+1). >> >> get_char() -> >> case io:get_chars("",1) of >> eof -> eof; >> [C] -> C >> end. >> $ >> >> _______________________________________________ >> erlang-questions mailing list >> erlang-questions@REDACTED >> http://www.erlang.org/mailman/listinfo/erlang-questions >> > > > From oscar@REDACTED Tue Apr 3 20:05:11 2007 From: oscar@REDACTED (Oscar =?ISO-8859-1?B?SGVsbHN0cvZt?=) Date: Tue, 3 Apr 2007 19:05:11 +0100 Subject: [erlang-questions] spawn race condition? In-Reply-To: <200704040301.16065.als@iinet.net.au> References: <200704040301.16065.als@iinet.net.au> Message-ID: <20070403190511.22fca320@linux.site> On Wed, 4 Apr 2007 04:01:16 +1100 Anthony Shipman wrote: > I have code that looks like this: > > call(Phone) -> > Pid = spawn(?MODULE, init, [Phone]), > > util:delay(100), > Pid! {startCall, self()}, > receive > callComplete -> {ok, Pid} > after > 5000 -> false > end. > > If I don't have the 100ms delay then the only message that the new process > receives is the integer 0. It works with the delay. Am I missing something? What exactly does init/1 do? You are indeed supposed to be able to send messages to processes without delays. Are there any other processes sending the spawned processes if it would return {ok, Pid}? Does init somehow flush the message queue? > -- > Anthony Shipman Mamas don't let your babies > als@REDACTED grow up to be outsourced. > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions -- Oscar Hellstr?m, oscar@REDACTED Erlang Training and Consulting http://www.erlang-consulting.com/ From miguelrubinos@REDACTED Tue Apr 3 21:33:43 2007 From: miguelrubinos@REDACTED (=?ISO-8859-1?Q?Miguel_Rodr=EDguez_Rubinos?=) Date: Tue, 3 Apr 2007 21:33:43 +0200 Subject: [erlang-questions] Debian ARM: Three beam processes Message-ID: <3fc99f280704031233n4144383bn48acfedc2673109e@mail.gmail.com> Hello all, I've realised a curious behaviour in erlang debian package. When I call erl, three processes are created with the same erlang name, as you can see below. I know this is not usual (at least in Mac OS X and FreeBSD in which I usually develop), any idea? Help would be appreciated... I'm using Debian: Linux bs0 2.6.18-3-ixp4xx #1 Tue Dec 5 16:52:07 UTC 2006 armv5tel GNU/Linux ARM Architecture: XScale-IXP42x Family rev 1 (v5l) Erlang package version is 11.b.2-4. The unusual behaviour: $ ps ax |grep beam 2569 pts/0 S+ 0:00 grep beam $ erl -sname dontknowwhy -detached $ ps ax |grep beam 2581 pts/0 S 0:01 /usr/lib/erlang/erts-5.5.2/bin/beam -- -root /usr/lib/erlang -progname erl -- -home /home/mrrubinos -sname dontknowwhy -noshell -noinput 2582 pts/0 S 0:00 /usr/lib/erlang/erts-5.5.2/bin/beam -- -root /usr/lib/erlang -progname erl -- -home /home/mrrubinos -sname dontknowwhy -noshell -noinput 2583 pts/0 S 0:00 /usr/lib/erlang/erts-5.5.2/bin/beam -- -root /usr/lib/erlang -progname erl -- -home /home/mrrubinos -sname dontknowwhy -noshell -noinput 2589 pts/0 S+ 0:00 grep beam One of the strangest things is that at this point there are three erlang nodes with the same name and no erl_crash.dump. Thanks in advance, Miguel -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob@REDACTED Tue Apr 3 19:52:23 2007 From: bob@REDACTED (Bob Ippolito) Date: Tue, 3 Apr 2007 10:52:23 -0700 Subject: [erlang-questions] spawn race condition? In-Reply-To: <200704040301.16065.als@iinet.net.au> References: <200704040301.16065.als@iinet.net.au> Message-ID: <6a36e7290704031052j7cf9f82eqba79f01b9f646dd@mail.gmail.com> On 4/3/07, Anthony Shipman wrote: > I have code that looks like this: > > call(Phone) -> > Pid = spawn(?MODULE, init, [Phone]), > > util:delay(100), > Pid! {startCall, self()}, > receive > callComplete -> {ok, Pid} > after > 5000 -> false > end. > > If I don't have the 100ms delay then the only message that the new process > receives is the integer 0. It works with the delay. Am I missing something? spawn is async. You should have it message back on startup to notify that it's running, that way you can make it sync. Surely OTP does this somewhere.. but it'd look something like this: spawn_sync(Fun) -> Self = self(), F = fun () -> Self ! {started, self()}, Fun() end, Pid = spawn(F), receive {started, Pid} -> Pid; after 5000 -> error end. From rickard.s.green@REDACTED Tue Apr 3 22:14:37 2007 From: rickard.s.green@REDACTED (Rickard Green) Date: Tue, 03 Apr 2007 22:14:37 +0200 Subject: [erlang-questions] Debian ARM: Three beam processes In-Reply-To: <3fc99f280704031233n4144383bn48acfedc2673109e@mail.gmail.com> References: <3fc99f280704031233n4144383bn48acfedc2673109e@mail.gmail.com> Message-ID: <4612B5AD.7040305@ericsson.com> When linuxthreads is used, all threads show up in process listings. Try adding +A10 (which creates ten async-threads in the emulator) to the erl command line and you will get even more beam processes reported by ps. BR, Rickard Green, Erlang/OTP, Ericsson AB. Miguel Rodr?guez Rubinos wrote: > Hello all, > > I've realised a curious behaviour in erlang debian package. When I > call erl, three processes are created with the same erlang name, as > you can see below. I know this is not usual (at least in Mac OS X and > FreeBSD in which I usually develop), any idea? Help would be > appreciated... > > I'm using Debian: Linux bs0 2.6.18-3-ixp4xx #1 Tue Dec 5 16:52:07 UTC > 2006 armv5tel GNU/Linux > ARM Architecture: XScale-IXP42x Family rev 1 (v5l) > Erlang package version is 11.b.2-4. > > The unusual behaviour: > > $ ps ax |grep beam > 2569 pts/0 S+ 0:00 grep beam > > $ erl -sname dontknowwhy -detached > > $ ps ax |grep beam > 2581 pts/0 S 0:01 /usr/lib/erlang/erts- 5.5.2/bin/beam -- -root > /usr/lib/erlang -progname erl -- -home /home/mrrubinos -sname > dontknowwhy -noshell -noinput > 2582 pts/0 S 0:00 /usr/lib/erlang/erts-5.5.2/bin/beam -- -root > /usr/lib/erlang -progname erl -- -home /home/mrrubinos -sname > dontknowwhy -noshell -noinput > 2583 pts/0 S 0:00 /usr/lib/erlang/erts-5.5.2/bin/beam -- -root > /usr/lib/erlang -progname erl -- -home /home/mrrubinos -sname > dontknowwhy -noshell -noinput > 2589 pts/0 S+ 0:00 grep beam > > One of the strangest things is that at this point there are three > erlang nodes with the same name and no erl_crash.dump. > > Thanks in advance, > > Miguel > > > ------------------------------------------------------------------------ > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions From waldemar.rachwal@REDACTED Wed Apr 4 10:55:56 2007 From: waldemar.rachwal@REDACTED (Waldemar Rachwal) Date: Wed, 4 Apr 2007 10:55:56 +0200 Subject: [erlang-questions] CEAN Contributions Message-ID: Christophe, Any realistic date when the release comes up? For a start it might be just 1.2 ;) Regards, WR. On 3/26/07, Christophe Romain wrote: > > This week CEAN 1.3 will be released with many improvements, new > packages and bug corrections. From CEAN 1.3, all packages will > include there .pub file. All .pub files will also be downloadable > from the contribution web page. > From psa@REDACTED Wed Apr 4 11:11:42 2007 From: psa@REDACTED (=?ISO-8859-1?Q?Paulo_S=E9rgio_Almeida?=) Date: Wed, 04 Apr 2007 10:11:42 +0100 Subject: [erlang-questions] Replacing ets tables - renaming and race condition Message-ID: <46136BCE.6020805@di.uminho.pt> I want to make some computation periodically, e.g. one a minute, and store the results into an ets table. To allow other processes to lookup values any time, before the whole computation is finished (and as the computation must start from an empty table which gets filled, and can take some time), I work on a temporary table and then rename it to the one looked up by other processes. But if I do: Tab = ets:new(tmp, [named_table]), compute(Tab), ets:rename(tmp, used_table) this causes an exception if used_table already exists. On the other hand, if I delete the original table: Tab = ets:new(tmp, [named_table]), compute(Tab), ets:delete(used_table), ets:rename(tmp, used_table) there is the possible race of someone trying to look it up before the rename. I assume this pattern must have occurred to someone. How can the race be avoided? (Btw, In my case there is no need for "transactions" involving several lookups in the table same, and no problem if some process does two consecutive lookups, one in the "old" table and the other in the "new" table.) I understand that the rename causes an exception to avoid acidentally destroying tables. But it would be useful to have a variant that renames and deletes atomically, if the target exists, maybe with an extra "force" parameter. e.g.: ets:rename(from, to, true) Paulo From christophe.romain@REDACTED Wed Apr 4 11:03:26 2007 From: christophe.romain@REDACTED (Christophe Romain) Date: Wed, 4 Apr 2007 11:03:26 +0200 Subject: [erlang-questions] CEAN Contributions In-Reply-To: References: Message-ID: <5D16F5B9-5B10-4022-8E6A-2E38BEBAD73A@process-one.net> yes it's version 1.2 packages are ready, builds of R11B-4 ok for windows linux-x86 and MacOSX release is a question of days, i first planed to release last week end, i'll do my best to do it this week. From denis.bilenko@REDACTED Wed Apr 4 12:22:17 2007 From: denis.bilenko@REDACTED (Denis Bilenko) Date: Wed, 4 Apr 2007 17:22:17 +0700 Subject: [erlang-questions] Wrapping C libraries in pure Erlang Message-ID: <95d6e98c0704040322m6f661342l2bb1df78c66b7c40@mail.gmail.com> Hello, Python has a very nice package in its stdlib -- ctypes. It allows wrapping C libraries in pure Python. ctypes' implementation is based on libffi, C library for handling dynamic libraries. I wonder if Erlang could have such library, implemented as a driver on top of libffi, or any other way that serves the goal. Excluding intermediate IDL and associated compilation phase simplifies interop a lot. Surely, one could crash an interpreter more easily, but that can be mitigated by separating unsafe code in another node. A couple examples from ctypes documentation translated into (wishful) Erlang: %% Functions return int by default 1> cee:call(Libc, time, [null]). 1150640792 %% Parameters' types deduced when there exists a well-defined mapping 2> cee:call(Libc, printf, ["%d bottles of beer\n", 42]). %% Ambiguity must be resolved by user 3> cee:call(Libc, printf, ["%d bottles of beer\n", 42.5]). % float or double? ** exited: {{nocatch,{argument_error, 2}}, [{erl_eval,do_apply,5},{shell,exprs,6},{shell,eval_loop,3}]} ** 4> cee:call(Libc, printf, ["int %d, double %f\n", 1234, cee:double(3.14)]). int 1234, double 3.1400001049 31 %% where cee:double is something like double(N) when is_float(N) -> {c_double, N}. %% This example is somewhat different from Python's, %% since Erlang disallows mutable data. Although, that %% doesn't seem a big problem, as we can make more copies. 5> cee:call(Libc, sscanf, ["1 3.14 Hello", "%d %f %s", output(c_int), output(c_float), output(char_array(100))]). {3, [1, 3.1400001049, "Hello"]}. (ctypes has much more than that, including passing python functions as callbacks) One useful application would be accessing system calls not covered by existing BIFs/drivers (native GUI goes in this category) I would like to hear any comments, especially from people who know something about Erlang internals (I don't): Would it be hard to implement? Has anyone already thought of something like that? Denis. From als@REDACTED Wed Apr 4 12:50:01 2007 From: als@REDACTED (Anthony Shipman) Date: Wed, 4 Apr 2007 20:50:01 +1000 Subject: [erlang-questions] spawn race condition? In-Reply-To: <20070403190511.22fca320@linux.site> References: <200704040301.16065.als@iinet.net.au> <20070403190511.22fca320@linux.site> Message-ID: <200704042050.01519.als@iinet.net.au> On Wed, 4 Apr 2007 04:05 am, Oscar Hellstr?m wrote: > On Wed, 4 Apr 2007 04:01:16 +1100 > > Anthony Shipman wrote: > > I have code that looks like this: > > > > call(Phone) -> > > Pid = spawn(?MODULE, init, [Phone]), > > > > util:delay(100), > > Pid! {startCall, self()}, > > receive > > callComplete -> {ok, Pid} > > after > > 5000 -> false > > end. > > > > If I don't have the 100ms delay then the only message that the new > > process receives is the integer 0. It works with the delay. Am I missing > > something? > > What exactly does init/1 do? You are indeed supposed to be able to send > messages to processes without delays. Are there any other processes > sending the spawned processes if it would return {ok, Pid}? Does init > somehow flush the message queue? These are good questions which led me to the bug. init was contacting another process which wasn't well written. Thanks for the help. -- Anthony Shipman Mamas don't let your babies als@REDACTED grow up to be outsourced. From psa@REDACTED Wed Apr 4 12:56:53 2007 From: psa@REDACTED (=?ISO-8859-1?Q?Paulo_S=E9rgio_Almeida?=) Date: Wed, 04 Apr 2007 11:56:53 +0100 Subject: [erlang-questions] Replacing ets tables - renaming and race condition In-Reply-To: <8209f740704040239x700ca3e4v1e61f6eb60bdf742@mail.gmail.com> References: <46136BCE.6020805@di.uminho.pt> <8209f740704040239x700ca3e4v1e61f6eb60bdf742@mail.gmail.com> Message-ID: <46138475.9000809@di.uminho.pt> Ulf, even if my problem is much simpler than if there were dependencies between lookups, it is not that simple ... Namely, your sketched solution still has a race condition. > Tab = ets:new(tmp, []), > compute(Tab), > ets:insert(switch_table, {current, Tab}). If some process does: > lookup(Key) -> > Tab = ets:lookup_element(switch, current, 2), > ets:lookup(Tab, Key). it could do the lookup_element, but be interrupted before doing the lookup. This means the lookup could be to a table that no longer exists if the recompute is: > recompute() -> > Old = ets:lookup_element(switch, current, 2), > New = ets:new(tmp, []), > compute(New), > ets:insert(switch, {current, New}), > ets:delete(Old). So, we still have a problem :) Moreover, this switch table would make usage a bit unpleasant. To make this thread more interesting, as mnesia/ets is the erlang "shared memory", I am curious how frequently do people encounter these kind of race conditions and what (minimal) support there should be towards enabling fast accesses while ensuring something, like atomicity (e.g. like update_counter). What do you think about my "rename with forced atomic delete" proposal. I think it could have its place. Regards, Paulo From ulf.wiger@REDACTED Wed Apr 4 13:19:52 2007 From: ulf.wiger@REDACTED (Ulf Wiger (TN/EAB)) Date: Wed, 4 Apr 2007 13:19:52 +0200 Subject: [erlang-questions] Replacing ets tables - renaming and race condition In-Reply-To: <46138475.9000809@di.uminho.pt> Message-ID: <6616D98C65DD514BA2E1DDC5F92231550191853E@esealmw115.eemea.ericsson.se> What you're saying is basically that the purging problem exists even for your program... Why, of course, and this is the eternal crux with trying to find a low-cost shared-memory solution to race conditions. (: The easiest way to solve the race condition is to serialize access via a process. You could also use global:trans(), which more or less amounts to the same thing. Perhaps a less destructive BIF would be: ets:switch_names(Named_table1, Named_table2). This way, one could easily flip between an 'inactive' and 'active' table, without having to forcibly destroy data just to do the switch. Presumably, the function would exit with badarg if either table is not a named_table. This would be in line with Erlang's telecom tradition, since active/passive tables are a common way to deal with subscriber lookup. Operators enjoy maintaining a passive table of subscriber data, and then issue an 'activate' command, flipping the status of the passive table to active, and vice versa. BR, Ulf W > -----Original Message----- > From: erlang-questions-bounces@REDACTED > [mailto:erlang-questions-bounces@REDACTED] On Behalf Of > Paulo S?rgio Almeida > Sent: den 4 april 2007 12:57 > To: Ulf Wiger > Cc: erlang-questions@REDACTED > Subject: Re: [erlang-questions] Replacing ets tables - > renaming and race condition > > Ulf, even if my problem is much simpler than if there were > dependencies between lookups, it is not that simple ... > > Namely, your sketched solution still has a race condition. > > > Tab = ets:new(tmp, []), > > compute(Tab), > > ets:insert(switch_table, {current, Tab}). > > If some process does: > > > lookup(Key) -> > > Tab = ets:lookup_element(switch, current, 2), > > ets:lookup(Tab, Key). > > it could do the lookup_element, but be interrupted before > doing the lookup. This means the lookup could be to a table > that no longer exists if the recompute is: > > > recompute() -> > > Old = ets:lookup_element(switch, current, 2), > > New = ets:new(tmp, []), > > compute(New), > > ets:insert(switch, {current, New}), > > ets:delete(Old). > > So, we still have a problem :) > Moreover, this switch table would make usage a bit unpleasant. > > To make this thread more interesting, as mnesia/ets is the > erlang "shared memory", I am curious how frequently do people > encounter these kind of race conditions and what (minimal) > support there should be towards enabling fast accesses while > ensuring something, like atomicity (e.g. like update_counter). > > What do you think about my "rename with forced atomic delete" > proposal. > I think it could have its place. > > Regards, > Paulo > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From ulf.wiger@REDACTED Wed Apr 4 13:22:16 2007 From: ulf.wiger@REDACTED (Ulf Wiger (TN/EAB)) Date: Wed, 4 Apr 2007 13:22:16 +0200 Subject: [erlang-questions] Replacing ets tables - renaming and race condition In-Reply-To: <46138475.9000809@di.uminho.pt> Message-ID: <6616D98C65DD514BA2E1DDC5F92231550191854B@esealmw115.eemea.ericsson.se> Apologies, btw. I have my wiger.net emails forwarded to my gmail account, but the gmail account doesn't subscribe to the list. That's why this post didn't make it through to the list. BR, Ulf W > -----Original Message----- > From: erlang-questions-bounces@REDACTED > [mailto:erlang-questions-bounces@REDACTED] On Behalf Of > Paulo S?rgio Almeida > Sent: den 4 april 2007 12:57 > To: Ulf Wiger > Cc: erlang-questions@REDACTED > Subject: Re: [erlang-questions] Replacing ets tables - > renaming and race condition > > Ulf, even if my problem is much simpler than if there were > dependencies between lookups, it is not that simple ... > > Namely, your sketched solution still has a race condition. > > > Tab = ets:new(tmp, []), > > compute(Tab), > > ets:insert(switch_table, {current, Tab}). > > If some process does: > > > lookup(Key) -> > > Tab = ets:lookup_element(switch, current, 2), > > ets:lookup(Tab, Key). > > it could do the lookup_element, but be interrupted before > doing the lookup. This means the lookup could be to a table > that no longer exists if the recompute is: > > > recompute() -> > > Old = ets:lookup_element(switch, current, 2), > > New = ets:new(tmp, []), > > compute(New), > > ets:insert(switch, {current, New}), > > ets:delete(Old). > > So, we still have a problem :) > Moreover, this switch table would make usage a bit unpleasant. > > To make this thread more interesting, as mnesia/ets is the > erlang "shared memory", I am curious how frequently do people > encounter these kind of race conditions and what (minimal) > support there should be towards enabling fast accesses while > ensuring something, like atomicity (e.g. like update_counter). > > What do you think about my "rename with forced atomic delete" > proposal. > I think it could have its place. > > Regards, > Paulo > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From surindar.shanthi@REDACTED Wed Apr 4 13:38:50 2007 From: surindar.shanthi@REDACTED (Surindar Sivanesan) Date: Wed, 4 Apr 2007 17:08:50 +0530 Subject: [erlang-questions] Startting erlang application using services in Windows. Message-ID: <42ea5fb60704040438g7df7e814u7ccbe09efbe1bc5e@mail.gmail.com> Dear all, I want to start my erlang application using services in Windows. I have created the release for that erlang application. I have created .rel file and .app file and then used systools:make_script/2, systools:script2boot/1 and systools:make_tar/1 for creating the release. Then I use erlsrv to create the service. Then I'm unable to proceed further to start the application using service. It would be very helpful if you guide me in starting the application using services. Note: I'm using Windows XP. -- with regards, S.Surindar -------------- next part -------------- An HTML attachment was scrubbed... URL: From richardc@REDACTED Wed Apr 4 13:54:04 2007 From: richardc@REDACTED (Richard Carlsson) Date: Wed, 04 Apr 2007 13:54:04 +0200 Subject: [erlang-questions] Replacing ets tables - renaming and race condition In-Reply-To: <46136BCE.6020805@di.uminho.pt> References: <46136BCE.6020805@di.uminho.pt> Message-ID: <461391DC.9080208@it.uu.se> Paulo S?rgio Almeida wrote: > I work on a temporary table and then rename it to the > one looked up by other processes. But if I do: > > Tab = ets:new(tmp, [named_table]), > compute(Tab), > ets:rename(tmp, used_table) > > this causes an exception if used_table already exists. On the other > hand, if I delete the original table: > > Tab = ets:new(tmp, [named_table]), > compute(Tab), > ets:delete(used_table), > ets:rename(tmp, used_table) > > there is the possible race of someone trying to look it up before the > rename. I assume this pattern must have occurred to someone. How can the > race be avoided? The obvious long-term solution is that ets could use an atomic switch operation. Since the intention is that clients call ets:...() functions directly, it is also the responsibility of the ets API to provide the necessary primitives. A short term solution (if you have control over the code for the clients) is to _not_ let them call ets directly. (But for efficiency reasons, you probably don't want to hide the ets tables behind a serialising server process.) A reasonable solution, then, is to have the clients access the ets tables solely through your own lookup functions, which implement a catch-wait-retry loop (with incremental back-off and some limit on the number of retries) around the actual ets calls, to hide the fact that once in a while the table might be missing for a brief moment. /Richard From adam@REDACTED Wed Apr 4 15:03:15 2007 From: adam@REDACTED (Adam Lindberg) Date: Wed, 4 Apr 2007 15:03:15 +0200 Subject: [erlang-questions] Start module In-Reply-To: <000c01c77483$d576a9d0$0300a8c0@st.se> References: <000c01c77483$d576a9d0$0300a8c0@st.se> Message-ID: <6344005f0704040603l1197115co3c01dc06ae67e33e@mail.gmail.com> Another thing you might want to look at is to make an OTP application of your code. Then you can start and stop your project / application and do special init stuff. Check out applications under: http://erlang.org/doc/doc-5.5.4/doc/design_principles/part_frame.html Cheers! Adam On 4/1/07, Lennart Ohman wrote: > Hi Fredrik, > I am not sure if I now answer something in the middle of a > thread, but unless you have done something to your Erlang > system, modules are automatically loaded on demand. The l/1 > shell function you are referring to is only necessary if you > want to reload the module (like after you have a bew better > version available). > > If reloading modules in runtime *is* what you want to do and > you want it to be done in som "automagic" way, you need to > look at the API of 'code'. What you will be doing in that case > is actually building a kind of release handler, and requires > understanding of the new/old code concepts. > > Best Regards > > Lennart > > ------------------------------------------------------------- > Lennart Ohman office : +46-8-587 623 27 > Sjoland & Thyselius Telecom AB cellular: +46-70-552 67 35 > H?lsingegatan 43, 10tr fax : +46-8-667 82 30 > SE-113 31, STOCKHOLM, SWEDEN email : lennart.ohman@REDACTED > > -----Original Message----- > > From: erlang-questions-bounces@REDACTED [mailto:erlang-questions- > > bounces@REDACTED] On Behalf Of Fredrik Hoback > > Sent: Sunday, April 01, 2007 11:21 AM > > To: erlang-questions@REDACTED > > Subject: [erlang-questions] Start module > > > > Hi, I have a project that I'm working on which consists of several > > modules. These has to be loaded ( l(my_module). ) and started in a special > > order. Since I have 5 modules it is cumbersome to do this every time. Is > > it possible to construct a new module that does this? It should first load > > some modules then start them? > > ------------------------------------ > > Fredrik Hoback > > fredrik.hoback@REDACTED > > > > > > > > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- Adam Lindberg Software Developer Erlang Training and Consulting Ltd 401 Fruit and Wool Exchange, Brushfield Street, London, E1 6EL, United Kingdom Company Registration 3893360 VAT Number GB 752 1091 57 Tel +44 207 456 1020 Fax +44 870 1390 779 Mobile +44 7960 726 016 Email adam@REDACTED From mats.cronqvist@REDACTED Wed Apr 4 15:23:04 2007 From: mats.cronqvist@REDACTED (Mats Cronqvist) Date: Wed, 04 Apr 2007 15:23:04 +0200 Subject: [erlang-questions] Replacing ets tables - renaming and race condition In-Reply-To: <46138475.9000809@di.uminho.pt> References: <46136BCE.6020805@di.uminho.pt> <8209f740704040239x700ca3e4v1e61f6eb60bdf742@mail.gmail.com> <46138475.9000809@di.uminho.pt> Message-ID: <4613A6B8.9080902@ericsson.com> Paulo S?rgio Almeida wrote: > Ulf, even if my problem is much simpler than if there were dependencies > between lookups, it is not that simple ... > > Namely, your sketched solution still has a race condition. > >> Tab = ets:new(tmp, []), >> compute(Tab), >> ets:insert(switch_table, {current, Tab}). > > If some process does: > >> lookup(Key) -> >> Tab = ets:lookup_element(switch, current, 2), >> ets:lookup(Tab, Key). > > it could do the lookup_element, but be interrupted before doing the > lookup. This means the lookup could be to a table that no longer exists > if the recompute is: > >> recompute() -> >> Old = ets:lookup_element(switch, current, 2), >> New = ets:new(tmp, []), >> compute(New), >> ets:insert(switch, {current, New}), >> ets:delete(Old). > > So, we still have a problem : we still have a problem if and only if recompute insists on deleting the old table. what you're shooting for is having all ets access look something like this; Tab = get_current_tab(), do_all_kinds_of_ets_stuff(Tab) where Tab must not disappear while we're in do_all_kinds_of_ets_stuff/1. realistically, the time spent in do_all_kinds_of_ets_stuff/1 is much less than the time between calls to recompute/0. if so, something like this would do. recompute() -> New = ets:new(tmp, []), Current = ets:lookup_element(switch, current, 2), Old = ets:lookup_element(switch, old, 2), compute(New), ets:insert(switch, {current, New}), ets:insert(switch, {old, Current}), ets:delete(Old). mats From mats.cronqvist@REDACTED Wed Apr 4 16:05:41 2007 From: mats.cronqvist@REDACTED (Mats Cronqvist) Date: Wed, 04 Apr 2007 16:05:41 +0200 Subject: [erlang-questions] Wrapping C libraries in pure Erlang In-Reply-To: <95d6e98c0704040322m6f661342l2bb1df78c66b7c40@mail.gmail.com> References: <95d6e98c0704040322m6f661342l2bb1df78c66b7c40@mail.gmail.com> Message-ID: <4613B0B5.1090901@ericsson.com> Denis Bilenko wrote: [...] > One useful application would be accessing system calls not > covered by existing BIFs/drivers (native GUI goes in this > category) > > I would like to hear any comments, especially from people who > know something about Erlang internals (I don't): > Would it be hard to implement? > Has anyone already thought of something like that? i think the "proper" way to wrap external libraries (esp native GUI) is to create a c-node (i.e. a server process that implements the erlang distribution protocol). the call to time() is wrapped in (say) Time(), accessible thus; libc ! {'Time',[]}, receive {libc,{ok,Ans}} -> Ans end many/most wrappers can be auto generated from the C header files. this is verifiably possible (and even easy), since I've done exactly this with GTK (http://code.google.com/p/gtknode). a c-node is safe and easy to work with. in my experience, linked in drivers are more trouble than their worth. mats From serge@REDACTED Wed Apr 4 16:16:18 2007 From: serge@REDACTED (Serge Aleynikov) Date: Wed, 04 Apr 2007 10:16:18 -0400 Subject: [erlang-questions] Wrapping C libraries in pure Erlang In-Reply-To: <95d6e98c0704040322m6f661342l2bb1df78c66b7c40@mail.gmail.com> References: <95d6e98c0704040322m6f661342l2bb1df78c66b7c40@mail.gmail.com> Message-ID: <4613B332.4050207@hq.idt.net> Part of the issue is that this approach would make it possible for a function call inside a 3rd party library to block for a while. Since Erlang's concurrency is dependent on the fact that function calls are very short, and the emulator uses reduction-based counting for giving CPU slices to each light-weight process a blocking call would significantly inhibit concurrency. Drivers solve this problem by allowing asynchronous invocation of blocking functions in the context of threads different from the emulator(s) (*). In case of a driver or a port, once you are on the C-side of coding interface, you can make calls to any 3rd party library directly without needing FFI (except for cases of functions with variable arguments), which may bring you to the question of why bother with such an Erlang library if you already have ports and drivers that can be written in C or even ei interface for writing C-nodes that can make any C-calls safely with respect to the emulator? There were attempts at somewhat automating generation of a driver using EDTK tooklit (**) or Dryverl (***) that some people found useful. Others prefer having more control and coding drivers by hand. Regards, Serge (*) Emulators can run in multiple threads if SMP support is enabled. (**) http://www.snookles.com/erlang/edtk/ (***) http://forge.objectweb.org/forum/forum.php?forum_id=1018 Denis Bilenko wrote: > Hello, > > Python has a very nice package in its stdlib -- ctypes. It allows > wrapping C libraries in pure Python. ctypes' implementation is based > on libffi, C library for handling dynamic libraries. > > I wonder if Erlang could have such library, implemented as a driver on > top of libffi, or any other way that serves the goal. Excluding > intermediate IDL and associated compilation phase > simplifies interop a lot. Surely, one could crash an interpreter more > easily, but that can be mitigated by separating unsafe code in another > node. > > A couple examples from ctypes documentation translated into (wishful) Erlang: > > %% Functions return int by default > 1> cee:call(Libc, time, [null]). > 1150640792 > > %% Parameters' types deduced when there exists a well-defined mapping > 2> cee:call(Libc, printf, ["%d bottles of beer\n", 42]). > > %% Ambiguity must be resolved by user > 3> cee:call(Libc, printf, ["%d bottles of beer\n", 42.5]). % float or double? > ** exited: {{nocatch,{argument_error, 2}}, > [{erl_eval,do_apply,5},{shell,exprs,6},{shell,eval_loop,3}]} ** > > 4> cee:call(Libc, printf, ["int %d, double %f\n", 1234, cee:double(3.14)]). > int 1234, double 3.1400001049 > 31 > > %% where cee:double is something like > double(N) when is_float(N) -> {c_double, N}. > > %% This example is somewhat different from Python's, > %% since Erlang disallows mutable data. Although, that > %% doesn't seem a big problem, as we can make more copies. > 5> cee:call(Libc, sscanf, ["1 3.14 Hello", "%d %f %s", > output(c_int), output(c_float), > output(char_array(100))]). > {3, [1, 3.1400001049, "Hello"]}. > > (ctypes has much more than that, including passing python > functions as callbacks) > > One useful application would be accessing system calls not > covered by existing BIFs/drivers (native GUI goes in this > category) > > I would like to hear any comments, especially from people who > know something about Erlang internals (I don't): > Would it be hard to implement? > Has anyone already thought of something like that? > > Denis. > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From olivier.boudeville@REDACTED Wed Apr 4 16:18:35 2007 From: olivier.boudeville@REDACTED (Olivier BOUDEVILLE) Date: Wed, 4 Apr 2007 16:18:35 +0200 Subject: [erlang-questions] Erlang on supercomputers Message-ID: Hi, first, sorry if the question is irrelevant, I am by no means an HPC or Erlang expert. I was wondering whether, for the simulation of a large-scale distributed system, one could use Erlang on a supercomputer such as an IBM's BlueGene/L (see http://en.wikipedia.org/wiki/Blue_Gene for a description). I know that such computers do not belong to the readily-supported platforms, and that even with the newly added SMP/multi-core features of the R11B it would not be a piece of cake, but technically I just cannot figure out what the porting effort to such "exotic" architectures could be. Knowing that each processor is a PowerPC (and that Erlang works on Mac) running a very minimal (very light-weight, mono-process) GNU/Linux OS with limited POSIX support, what I imagine is that it would be feasible to run on each of the, say, 4000 nodes, a stripped-down Erlang interpreter that would schedule itself (without much support of the OS, no light-weight threads) numerous interacting Erlang processes that could communicate preferably with other processes on the same node or, otherwise, with processes running on close nodes. Is having Erlang running on these architectures technically possible with a limited porting effort ? If yes, am I correct to think that, provided we manage to place cleverly the concurrent processes (the more two of them are interacting, the "closest" they are in the communication topology, a three-dimensional torus), we could in some way take advantage of the message-passing nature of Erlang to use (even less-than-optimally) the processing power of these machines ? Another idea, still more hazardous : suppose one has a working MPI implementation on a given computer. Would it be possible to build a version of Erlang on top of it ? I believe they share at least some message-passing conventions... Thanks in advance for any hint, Olivier. PS : I will be out of the office for a while, but sure I will try to contribute to any mail exchange afterwards --------------------------- Olivier Boudeville EDF R&D : 1, avenue du G?n?ral de Gaulle, 92140 Clamart, France D?partement SINETICS, groupe ASICS (I2A), bureau C-052 Office : 33 1 47 65 59 58 / Mobile : 33 6 16 83 37 22 / Fax : 33 1 47 65 34 24 -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomasl_erlang@REDACTED Wed Apr 4 18:31:25 2007 From: thomasl_erlang@REDACTED (Thomas Lindgren) Date: Wed, 4 Apr 2007 09:31:25 -0700 (PDT) Subject: [erlang-questions] Replacing ets tables - renaming and race condition In-Reply-To: <46138475.9000809@di.uminho.pt> Message-ID: <998861.50448.qm@web38805.mail.mud.yahoo.com> --- Paulo S?rgio Almeida wrote: > Ulf, even if my problem is much simpler than if > there were dependencies > between lookups, it is not that simple ... > > Namely, your sketched solution still has a race > condition. > > > Tab = ets:new(tmp, []), > > compute(Tab), > > ets:insert(switch_table, {current, Tab}). > > If some process does: > > > lookup(Key) -> > > Tab = ets:lookup_element(switch, current, 2), > > ets:lookup(Tab, Key). > > it could do the lookup_element, but be interrupted > before doing the > lookup. This means the lookup could be to a table > that no longer exists > if the recompute is: > /.../ > To make this thread more interesting, as mnesia/ets > is the erlang > "shared memory", I am curious how frequently do > people encounter these > kind of race conditions and what (minimal) support > there should be > towards enabling fast accesses while ensuring > something, like atomicity > (e.g. like update_counter). For parallel code using sequences of ets operations, you run into potential race conditions all the time; my personal conclusion is that the ets API is fundamentally broken for this sort of use. I think this was discussed previously on this list under the heading "atomic ets" or something like that. I seem to remember that the conclusion at the time was that in general the safe approach is to use mnesia instead. And you can of course sometimes design your code to avoid the problem altogether. However, as far as I'm concerned, a better term storage API (that is, an ets replacement) would definitely be nice. Best, Thomas ____________________________________________________________________________________ Don't pick lemons. See all the new 2007 cars at Yahoo! Autos. http://autos.yahoo.com/new_cars.html From thomasl_erlang@REDACTED Wed Apr 4 18:44:18 2007 From: thomasl_erlang@REDACTED (Thomas Lindgren) Date: Wed, 4 Apr 2007 09:44:18 -0700 (PDT) Subject: [erlang-questions] Erlang on supercomputers In-Reply-To: Message-ID: <350767.73378.qm@web38802.mail.mud.yahoo.com> --- Olivier BOUDEVILLE wrote: > Hi, > > first, sorry if the question is irrelevant, I am by > no means an HPC or > Erlang expert. > > I was wondering whether, for the simulation of a > large-scale distributed > system, one could use Erlang on a supercomputer such > as an IBM's > BlueGene/L (see > http://en.wikipedia.org/wiki/Blue_Gene for a > description). ... > Knowing that each processor is a PowerPC (and that > Erlang works on Mac) > running a very minimal (very light-weight, > mono-process) GNU/Linux OS with > limited POSIX support, what I imagine is that it > would be feasible to run > on each of the, say, 4000 nodes, a stripped-down > Erlang interpreter that > would schedule itself (without much support of the > OS, no light-weight > threads) numerous interacting Erlang processes that > could communicate > preferably with other processes on the same node or, > otherwise, with > processes running on close nodes. > > Is having Erlang running on these architectures > technically possible with > a limited porting effort ? If yes, am I correct to > think that, provided we > manage to place cleverly the concurrent processes > (the more two of them > are interacting, the "closest" they are in the > communication topology, a > three-dimensional torus), we could in some way take > advantage of the > message-passing nature of Erlang to use (even > less-than-optimally) the > processing power of these machines ? As long as you're running some Unix-flavour, porting should be fairly straightforward. The regular Erlang VM is not excessively large either, so you could start out by just getting Erlang/OTP running and then pare things down. The snags I can see are: 1. Distributed Erlang could have scalability problems, since it by default uses a mesh of nodes the last time I looked. You may have to read up on "hidden nodes" to get this right. (I haven't studied this issue recently, however.) 2. BlueGene is basically a number cruncher, isn't it? While it's not hopeless to do that in Erlang, you probably want to implement the serious numerics in another language and link them up. Several methods are available. MPI: I'm not aware of any existing implementations. You can probably implement the MPI protocol in Erlang though. The bit syntax is handy for that sort of thing. Or perhaps link with an existing implementation. I think there is a section on how to implement the Erlang distribution protocol in the docs. Best, Thomas ____________________________________________________________________________________ The fish are biting. Get more visitors on your site using Yahoo! Search Marketing. http://searchmarketing.yahoo.com/arp/sponsoredsearch_v2.php From rdiaz02@REDACTED Wed Apr 4 19:52:05 2007 From: rdiaz02@REDACTED (Ramon Diaz-Uriarte) Date: Wed, 4 Apr 2007 19:52:05 +0200 Subject: [erlang-questions] Erlang on supercomputers In-Reply-To: <350767.73378.qm@web38802.mail.mud.yahoo.com> References: <350767.73378.qm@web38802.mail.mud.yahoo.com> Message-ID: <624934630704041052m2370b265oc32b202b347dccbe@mail.gmail.com> On 4/4/07, Thomas Lindgren wrote: > > --- Olivier BOUDEVILLE > wrote: > > > Hi, > > > > first, sorry if the question is irrelevant, I am by > > no means an HPC or > > Erlang expert. > > > > I was wondering whether, for the simulation of a > > large-scale distributed > > system, one could use Erlang on a supercomputer such > > as an IBM's > > BlueGene/L (see > > http://en.wikipedia.org/wiki/Blue_Gene for a > > description). > ... > > Knowing that each processor is a PowerPC (and that > > Erlang works on Mac) > > running a very minimal (very light-weight, > > mono-process) GNU/Linux OS with > > limited POSIX support, what I imagine is that it > > would be feasible to run > > on each of the, say, 4000 nodes, a stripped-down > > Erlang interpreter that > > would schedule itself (without much support of the > > OS, no light-weight > > threads) numerous interacting Erlang processes that > > could communicate > > preferably with other processes on the same node or, > > otherwise, with > > processes running on close nodes. > > > > Is having Erlang running on these architectures > > technically possible with > > a limited porting effort ? If yes, am I correct to > > think that, provided we > > manage to place cleverly the concurrent processes > > (the more two of them > > are interacting, the "closest" they are in the > > communication topology, a > > three-dimensional torus), we could in some way take > > advantage of the > > message-passing nature of Erlang to use (even > > less-than-optimally) the > > processing power of these machines ? > > As long as you're running some Unix-flavour, porting > should be fairly straightforward. The regular Erlang > VM is not excessively large either, so you could start > out by just getting Erlang/OTP running and then pare > things down. > > The snags I can see are: > > 1. Distributed Erlang could have scalability problems, > since it by default uses a mesh of nodes the last time > I looked. You may have to read up on "hidden nodes" to > get this right. (I haven't studied this issue > recently, however.) > > 2. BlueGene is basically a number cruncher, isn't it? > While it's not hopeless to do that in Erlang, you > probably want to implement the serious numerics in > another language and link them up. Several methods are > available. > I actually have a not unrelated problem (distributing number crunching computations on a cluster). I was under the impression that this might be a very reasonable way to go: have Erlang take care of distribution, etc, and do the number crunching in another language (e.g., C). Any specific catch? > MPI: I'm not aware of any existing implementations. > You can probably implement the MPI protocol in Erlang I must be missing something: having Erlang, why would one want to implement the MPI protocol? In my case, I am actually trying to substitute code I have that uses MPI by the scheme above; for instance, this ought to give me fault tolerance with a lot less cost than what I am currently doing (checking MPI did not crash, restarting MPI, etc, etc, plus lots of very cluster-dependent hacks). Best, R. > though. The bit syntax is handy for that sort of > thing. Or perhaps link with an existing > implementation. I think there is a section on how to > implement the Erlang distribution protocol in the > docs. > > Best, > Thomas > > > > > ____________________________________________________________________________________ > The fish are biting. > Get more visitors on your site using Yahoo! Search Marketing. > http://searchmarketing.yahoo.com/arp/sponsoredsearch_v2.php > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- Ramon Diaz-Uriarte Statistical Computing Team Structural Biology and Biocomputing Programme Spanish National Cancer Centre (CNIO) http://ligarto.org/rdiaz From denis.bilenko@REDACTED Wed Apr 4 20:30:50 2007 From: denis.bilenko@REDACTED (Denis Bilenko) Date: Thu, 5 Apr 2007 01:30:50 +0700 Subject: [erlang-questions] Wrapping C libraries in pure Erlang Message-ID: <95d6e98c0704041130q578fc7b5ja34b6f44b9233e10@mail.gmail.com> Mats Cronqvist wrote: > i think the "proper" way to wrap external libraries (esp native GUI) is to > create a c-node (i.e. a server process that implements the erlang distribution > protocol). the call to time() is wrapped in (say) Time(), accessible thus; > > libc ! {'Time',[]}, > receive > {libc,{ok,Ans}} -> Ans > end > > many/most wrappers can be auto generated from the C header files. > > this is verifiably possible (and even easy), since I've done exactly this > with GTK (http://code.google.com/p/gtknode). > > a c-node is safe and easy to work with. in my experience, linked in drivers > are more trouble than their worth. That's why I want an ultimate linked-in driver -- to abstract them out, and never have to work with them again (except, maybe, for performance reasons). c-node is safe to work with, but erlang-node is just as safe. and it must be easier to work with -- after all, it is a high-level dynamic Erlang versus C. A bridge between dynamic language interpreter and C can be build from either end. ctypes has demonstrated that building Python wrappers to C libraries in Python itself is a good thing (or at least a very easy thing:). I think that would be true for Erlang too. Thank you for the pointer. C-node around libffi can be useful, but it is limited compared to driver (but I can always turn driver into a separate node). What if I want to make just one system call? It doesn't seem natural to start a node for it. What if this call receives file descriptor? Now it doesn't even seem possible. Denis. From denis.bilenko@REDACTED Wed Apr 4 20:32:21 2007 From: denis.bilenko@REDACTED (Denis Bilenko) Date: Thu, 5 Apr 2007 01:32:21 +0700 Subject: [erlang-questions] Wrapping C libraries in pure Erlang Message-ID: <95d6e98c0704041132i1c0acdb5ld6535cf081ba24f1@mail.gmail.com> Serge Aleynikov wrote: > Part of the issue is that this approach would make it possible for a > function call inside a 3rd party library to block for a while. Since > Erlang's concurrency is dependent on the fact that function calls are > very short, and the emulator uses reduction-based counting for giving > CPU slices to each light-weight process a blocking call would > significantly inhibit concurrency. For that case, imaginary library 'cee' has function 'cast' that instructs driver to call function asynchronously, as you have mentioned below. > Drivers solve this problem by allowing asynchronous invocation of > blocking functions in the context of threads different from the > emulator(s) (*). In case of a driver or a port, once you are on the > C-side of coding interface, you can make calls to any 3rd party library > directly without needing FFI (except for cases of functions with > variable arguments), which may bring you to the question of why bother > with such an Erlang library if you already have ports and drivers that > can be written in C or even ei interface for writing C-nodes that can > make any C-calls safely with respect to the emulator? Because, if I had such a library I would not have to bother with C, ei, driver interface. The point is, why manipulate Erlang data structures from C instead of manipulating C data structures from Erlang. Latter approach has to be more productive for (Erlang) programmer. Denis. From thomasl_erlang@REDACTED Wed Apr 4 23:49:49 2007 From: thomasl_erlang@REDACTED (Thomas Lindgren) Date: Wed, 4 Apr 2007 14:49:49 -0700 (PDT) Subject: [erlang-questions] Erlang on supercomputers In-Reply-To: <624934630704041052m2370b265oc32b202b347dccbe@mail.gmail.com> Message-ID: <317481.57467.qm@web38805.mail.mud.yahoo.com> --- Ramon Diaz-Uriarte wrote: > I actually have a not unrelated problem > (distributing number crunching > computations on a cluster). I was under the > impression that this might > be a very reasonable way to go: have Erlang take > care of distribution, > etc, and do the number crunching in another language > (e.g., C). Any > specific catch? Not that I know of, apart from the previous message. I'm not aware of anyone using Erlang for these purposes, so you might be on your own when it comes down to implementation. Your data is probably just Erlang binaries, so sending them should be straightforward; performance could be an issue though (e.g., data copying between Erlang and your program?). (I wonder what performance would be like if work item data were simply read and written as files?) But whether this is a problem depends on the characteristics and requirements of your algorithms. If your algorithm needs barrier synchronization etc, I guess you probably will have to cook something up. It might not be too difficult to write that in Erlang. Best, Thomas ____________________________________________________________________________________ Bored stiff? Loosen up... Download and play hundreds of games for free on Yahoo! Games. http://games.yahoo.com/games/front From nils.muellner@REDACTED Thu Apr 5 01:38:21 2007 From: nils.muellner@REDACTED (=?ISO-8859-15?Q?Nils_M=FCllner?=) Date: Thu, 05 Apr 2007 01:38:21 +0200 Subject: [erlang-questions] Master Thesis Message-ID: <461436ED.3090002@heh.uni-oldenburg.de> Hi, several months ago i stumbled over a collection of theses regarding Erlang. I forgot the link, but in case someone is interested, i just finished my thesis "Simulation of Self-Stabilizing Distributed Algorithms to Determine Fault-Tolerance Measures" where i implemented a simulator using Erlang. Btw, i also implemented a $\chi^2$ test. I forgot the exact value, but it was somewhere above 99%. Cheers to all, tomorrow i will open my reward-bottle of finest midleton whiskey ;-) Kind regards, Nils From rdiaz02@REDACTED Thu Apr 5 01:47:56 2007 From: rdiaz02@REDACTED (Ramon Diaz-Uriarte) Date: Thu, 5 Apr 2007 01:47:56 +0200 Subject: [erlang-questions] Erlang on supercomputers In-Reply-To: <317481.57467.qm@web38805.mail.mud.yahoo.com> References: <624934630704041052m2370b265oc32b202b347dccbe@mail.gmail.com> <317481.57467.qm@web38805.mail.mud.yahoo.com> Message-ID: <624934630704041647xdaa702ag5a94971594636f4d@mail.gmail.com> On 4/4/07, Thomas Lindgren wrote: > > --- Ramon Diaz-Uriarte wrote: > > > > I actually have a not unrelated problem > > (distributing number crunching > > computations on a cluster). I was under the > > impression that this might > > be a very reasonable way to go: have Erlang take > > care of distribution, > > etc, and do the number crunching in another language > > (e.g., C). Any > > specific catch? > > Not that I know of, apart from the previous message. > > I'm not aware of anyone using Erlang for these > purposes, so you might be on your own when it comes > down to implementation. Your data is probably just > Erlang binaries, so sending them should be > straightforward; performance could be an issue though > (e.g., data copying between Erlang and your program?). > (I wonder what performance would be like if work item > data were simply read and written as files?) But > whether this is a problem depends on the > characteristics and requirements of your algorithms. > For now I am dealing with embarrassingly parallelizable problems, where the number crunching (both the parallelizable parte and several previous and posterior computations) is done by R and C. Reading/writing to a file could be the simpler route, to begin with. > If your algorithm needs barrier synchronization etc, I > guess you probably will have to cook something up. It > might not be too difficult to write that in Erlang. Yes, there are eventually several barriers where synchronization is necessary. I hadn't thought about this (I am still in the early stages of learning Erlang). Best, R. > > Best, > Thomas > > > > > ____________________________________________________________________________________ > Bored stiff? Loosen up... > Download and play hundreds of games for free on Yahoo! Games. > http://games.yahoo.com/games/front > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- Ramon Diaz-Uriarte Statistical Computing Team Structural Biology and Biocomputing Programme Spanish National Cancer Centre (CNIO) http://ligarto.org/rdiaz From darius@REDACTED Thu Apr 5 02:46:10 2007 From: darius@REDACTED (Darius Bacon) Date: Wed, 4 Apr 2007 17:46:10 -0700 (PDT) Subject: [erlang-questions] Erlang interns wanted Message-ID: <200704050046.l350kAlK023576@shell.accesscom.com> If you're a student who's good with Erlang and you might be interested in spending the summer hacking with it at Yahoo!'s Content Match group in Burbank, California, please email me at darius@REDACTED You must be able to work in the U.S. We're behind the contextual 'Ads by Yahoo!' you see on lots of websites. Cheers, Darius From rlenglet@REDACTED Thu Apr 5 02:54:56 2007 From: rlenglet@REDACTED (Romain Lenglet) Date: Thu, 05 Apr 2007 09:54:56 +0900 Subject: [erlang-questions] Wrapping C libraries in pure Erlang In-Reply-To: <95d6e98c0704041132i1c0acdb5ld6535cf081ba24f1@mail.gmail.com> References: <95d6e98c0704041132i1c0acdb5ld6535cf081ba24f1@mail.gmail.com> Message-ID: <461448E0.5010105@users.forge.objectweb.org> Denis Bilenko wrote: > Serge Aleynikov wrote: > >> Part of the issue is that this approach would make it possible for a >> function call inside a 3rd party library to block for a while. Since >> Erlang's concurrency is dependent on the fact that function calls are >> very short, and the emulator uses reduction-based counting for giving >> CPU slices to each light-weight process a blocking call would >> significantly inhibit concurrency. > > For that case, imaginary library 'cee' has function 'cast' that instructs > driver to call function asynchronously, as you have mentioned below. That does not work, because while an emulator scheduler's OS thread is calling C code, it cannot execute Erlang code. Even if your process uses cee or cast, the C code will still be executed using one of the scheduler's OS threads that are also used to execute Erlang code. There is no separate OS thread pool for Erlang and C code. Therefore, this doesn't solve the problem. There exists a separate OS thread pool for exclusive use by linked-in drivers, but your drivers must explicitly programmed to use them, and they have severe drawbacks, e.g., you cannot communicate with Erlang (i.e., send a message to an Erlang process) from within such an I/O thread. That is what Serge Aleynikov mentioned just below: >> Drivers solve this problem by allowing asynchronous invocation of >> blocking functions in the context of threads different from the >> emulator(s) (*). In case of a driver or a port, once you are on the >> C-side of coding interface, you can make calls to any 3rd party library >> directly without needing FFI (except for cases of functions with >> variable arguments), which may bring you to the question of why bother >> with such an Erlang library if you already have ports and drivers that >> can be written in C or even ei interface for writing C-nodes that can >> make any C-calls safely with respect to the emulator? > > Because, if I had such a library I would not have to bother > with C, ei, driver interface. > The point is, why manipulate Erlang data structures from C instead of > manipulating C data structures from Erlang. > Latter approach has to be more productive for (Erlang) programmer. To understand why this cannot be trivial using the current linked-in driver mechanism implementation, please read about EDTK and Dryverl: http://www.erlang.se/workshop/2002/Fritchie.pdf http://www.csg.is.titech.ac.jp/paper/lenglet2006dryverl.pdf There has also been IG around for some time, but it does not support linked-in drivers: http://www.bluetail.com/tobbe/ig/doc.new/ If you use anything else than BIFs, then one important drawback is that you *must* pass all data as serialized terms between Erlang and C code. (Except that in some cases, you can send binaries to a linked-in drivers by reference, but that is quite tricky, cf. the paper on Dryverl) The linked-in drivers mechanism was not designed to interface to arbitrary C code. It was designed to implement I/O drivers. Period. Using this mechanism for anything else is possible, but is painful, which motivated tools like EDTK and Dryverl. If you really want to "manuipulate C data structures from Erlang", then you must use BIFs, which are undocumented and unsupported, i.e., your BIFs' code will be dependent on one specific version of the emulator, and you will have to distribute your own modified emulator to users. Impractical. If it were that easy to do, please believe that such an automatic integration of C and Erlang would have been done a long time ago. (^_^) Therefore, I agree with Mats and Serge: if you need simple concurrency and flexibility, use C ports. Linked-in drivers potentially give better performance, but may not be worth the effort for your problems. -- Romain Lenglet From lcoquelle@REDACTED Thu Apr 5 03:04:55 2007 From: lcoquelle@REDACTED (Ludovic Coquelle) Date: Thu, 5 Apr 2007 09:04:55 +0800 Subject: [erlang-questions] http client and server: inets, ibrowse, yaws Message-ID: Hi, I am looking for advice about the inets standard modules of OTP for http connection. My first goal is to embed an HTTP client. I see a lot of applications using 'ibrowse' module. I would like to use inets only because it is in standard otp (no dependency). Can anyone give a quick difference between the two? Also I need to embed an simple HTTP server and got the same problem with using 'yaws' or inets 'httpd'. Furthermore I cannot figure out how to start httpd without config file or root directory ... yaws is simplest to embed. Any advice or comment is welcome, thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rlenglet@REDACTED Thu Apr 5 05:02:50 2007 From: rlenglet@REDACTED (Romain Lenglet) Date: Thu, 05 Apr 2007 12:02:50 +0900 Subject: [erlang-questions] Wrapping C libraries in pure Erlang In-Reply-To: <461448E0.5010105@users.forge.objectweb.org> References: <95d6e98c0704041132i1c0acdb5ld6535cf081ba24f1@mail.gmail.com> <461448E0.5010105@users.forge.objectweb.org> Message-ID: <461466DA.3040308@users.forge.objectweb.org> Romain Lenglet wrote: > Denis Bilenko wrote: >> Serge Aleynikov wrote: >> >>> Part of the issue is that this approach would make it possible for a >>> function call inside a 3rd party library to block for a while. Since >>> Erlang's concurrency is dependent on the fact that function calls are >>> very short, and the emulator uses reduction-based counting for giving >>> CPU slices to each light-weight process a blocking call would >>> significantly inhibit concurrency. >> For that case, imaginary library 'cee' has function 'cast' that instructs >> driver to call function asynchronously, as you have mentioned below. > > That does not work, because while an emulator scheduler's OS thread is > calling C code, it cannot execute Erlang code. Even if your process uses > cee or cast, the C code will still be executed using one of the > scheduler's OS threads that are also used to execute Erlang code. There > is no separate OS thread pool for Erlang and C code. Therefore, this > doesn't solve the problem. OK... now that my cups of coffee start having effect, I can clarify my paragraph above. Your hypothetical 'cee' library cannot be implemented in Erlang, since we have no control over the scheduler and the creation / allocation of scheduling OS threads from Erlang code, and any time Erlang code calls a BIF or interact with a linked-in driver, this is done in a scheduler's OS thread. If you have many simultaneous calls to C code from Erlang, which probability is increased when your calls to C code are blocking or take a long time, then you have less OS threads available from the pool to execute Erlang code. This could even stall or deadlock your application. If your library were in C, that would be OK, and the existing APIs are probably sufficient, but you have to do a lot to circumvent the limits of the asynchronous I/O threads, as I mentioned below: > There exists a separate OS thread pool for exclusive use by linked-in > drivers, but your drivers must explicitly programmed to use them, and > they have severe drawbacks, e.g., you cannot communicate with Erlang > (i.e., send a message to an Erlang process) from within such an I/O thread. That is the kind of problems that EDTK and Dryverl try to solve. No need for yet another 'cee' library, IMO. Particularly, Chris Newcombe seems to have done a great job dealing with heavy multithreading in linked-in drivers using EDTK. -- Romain Lenglet From tobbe@REDACTED Thu Apr 5 07:47:46 2007 From: tobbe@REDACTED (Torbjorn Tornkvist) Date: Thu, 05 Apr 2007 07:47:46 +0200 Subject: [erlang-questions] http client and server: inets, ibrowse, yaws In-Reply-To: References: Message-ID: Ludovic Coquelle skrev: > Hi, > I am looking for advice about the inets standard modules of OTP for http > connection. > > My first goal is to embed an HTTP client. I see a lot of applications > using 'ibrowse' module. I would like to use inets only because it is in > standard otp (no dependency). Can anyone give a quick difference between > the two? If you look into yaws_soap_srv.erl (in Yaws), you'll see a way of choosing ibrowse if it exist in the path, else fallback to the inets http-client. Cheers, Tobbe From heinrich@REDACTED Thu Apr 5 08:05:36 2007 From: heinrich@REDACTED (Heinrich Venter) Date: Thu, 5 Apr 2007 08:05:36 +0200 Subject: [erlang-questions] http client and server: inets, ibrowse, yaws In-Reply-To: References: Message-ID: <000001c77748$70ebf110$52c3d330$@com> It has been said before that the inets HTTP suite is mainly used by Ericsson to test other software with (Ingela Anderton 28 Nov 2005). As such I don't think it is intended for production use. The last time I used the inets HTTP client, (2005) the difference between it and ibrowse was that ibrowse worked with the servers I was connecting to, and the inets client did not. On the HTTP server side, unless you are making a VERY simple page I would really recommend you go with yaws. It gives you much more flexibility and is easier to configure and embed. The dependency you create is really not a big price to pay, and easy to manage. My 2c -]-[einrich From: erlang-questions-bounces@REDACTED [mailto:erlang-questions-bounces@REDACTED] On Behalf Of Ludovic Coquelle Sent: Thursday, April 05, 2007 3:05 AM To: Erlang Subject: [erlang-questions] http client and server: inets, ibrowse, yaws Hi, I am looking for advice about the inets standard modules of OTP for http connection. My first goal is to embed an HTTP client. I see a lot of applications using 'ibrowse' module. I would like to use inets only because it is in standard otp (no dependency). Can anyone give a quick difference between the two? Also I need to embed an simple HTTP server and got the same problem with using 'yaws' or inets 'httpd'. Furthermore I cannot figure out how to start httpd without config file or root directory ... yaws is simplest to embed. Any advice or comment is welcome, thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ingela@REDACTED Thu Apr 5 10:22:41 2007 From: ingela@REDACTED (Ingela Anderton Andin) Date: Thu, 05 Apr 2007 10:22:41 +0200 Subject: [erlang-questions] http client and server: inets, ibrowse, yaws In-Reply-To: References: Message-ID: <4614B1D1.8030806@erix.ericsson.se> > Hi, > I am looking for advice about the inets standard modules of OTP for http > connection. > My first goal is to embed an HTTP client. I see a lot of applications using > 'ibrowse' module. I would like to use inets only because it is in standard > otp (no dependency). Can anyone give a quick difference between the two? Well from the beginning there was no HTTP-client in OTP, and then one was contributed but it was not officially supported due to lack of resources. Alas the contributed one did not really have product quality so ibrowse was born. Now the OTP HTTP-client has been rewritten and has product quality,and hence is officially supported. We have also looked at ibrowse and taken influence from it to support all things that we thought it did good that was lacking in OTP. The OTP one also may support some things not supported by ibrowse, if that did not change since last time I looked at ibrowse. (Cookie handling I think was one of them.) > Also I need to embed an simple HTTP server and got the same problem with > using 'yaws' or inets 'httpd'. Furthermore I cannot figure out how to start > httpd without config file or root directory ... yaws is simplest to embed. This one is harder to answer. The intes httpd and yaws have different approaches and both have their pros and cons. The Inets one is very old and inspired by apache. It also has a lot of legacy, that I would rather get rid of but that is impossible as we have customers that use it a lot. I think that yaws is also used a lot in the open source community and I can see things I like about it. There is no officially supported way to start inets without a config file, although webtool does that. I would not really recommend using webtools strategy as it might change without warning. It's in the plans for inets to improve start strategies but I am not making any promises until when this will be ready. So I am afraid I can not really recommend one or the other it so much depends on what you value the most for your particular situation. Regards Ingela - OTP team From als@REDACTED Thu Apr 5 12:38:26 2007 From: als@REDACTED (Anthony Shipman) Date: Thu, 5 Apr 2007 20:38:26 +1000 Subject: [erlang-questions] an erlang "gotcha" Message-ID: <200704052038.26904.als@iinet.net.au> Is there a place where difficulties with erlang and their solutions are described? Perhaps another page at Trapexit. Here's one that got me. -module(g). -export([run/0]). run() -> Pid = spawn(fun() -> io:fwrite("spawned~n") end), L = [1, 2, 3], io:fwrite("Pid=~p L=~p~n", [Pid, L]), if is_pid(Pid) and L /= [] -> io:fwrite("it worked~n"); true -> io:fwrite("it failed~n") end. It prints out "it failed". If you change the 'and' to 'andalso' it works. -- Anthony Shipman Mamas don't let your babies als@REDACTED grow up to be outsourced. From ingela@REDACTED Thu Apr 5 13:04:36 2007 From: ingela@REDACTED (Ingela Anderton Andin) Date: Thu, 05 Apr 2007 13:04:36 +0200 Subject: [erlang-questions] erlang-questions Digest, Vol 9, Issue 10 In-Reply-To: References: Message-ID: <4614D7C4.3020706@erix.ericsson.se> erlang-questions-request@REDACTED wrote: > It has been said before that the inets HTTP suite is mainly used by Ericsson > to test other software with (Ingela Anderton 28 Nov 2005). As such I don't > think it is intended for production use. > > It is true that the HTTP webserver in inets was crated from Ericsson internal requierments and was never designed to be a mainstream "superduper" webserver. The inets webserver has no intention of compeating with yaws in that aspect. > The last time I used the inets HTTP client, (2005) the difference between it > and ibrowse was that ibrowse worked with the servers I was connecting to, > and the inets client did not. > That is a long time ago. The HTTP client of today is intended for general use and I think will work just fine. > On the HTTP server side, unless you are making a VERY simple page I would > really recommend you go with yaws. It gives you much more flexibility and > is easier to configure and embed. > > > If the purpose is to build a big dynamic-website you would probably be better of with yaws. As I said before it depends on the problem. Regards Ingela -OTP team From seb-cl-mailist@REDACTED Thu Apr 5 13:11:27 2007 From: seb-cl-mailist@REDACTED (=?ISO-8859-1?Q?S=E9bastien_Saint-Sevin?=) Date: Thu, 05 Apr 2007 13:11:27 +0200 Subject: [erlang-questions] an erlang "gotcha" In-Reply-To: <200704052038.26904.als@iinet.net.au> References: <200704052038.26904.als@iinet.net.au> Message-ID: <4614D95F.4030208@matchix.com> > Is there a place where difficulties with erlang and their solutions are > described? Perhaps another page at Trapexit. > > Here's one that got me. > > -module(g). > -export([run/0]). > > run() -> > Pid = spawn(fun() -> io:fwrite("spawned~n") end), > L = [1, 2, 3], > io:fwrite("Pid=~p L=~p~n", [Pid, L]), > if > is_pid(Pid) and L /= [] -> For what you want, it should be : is_pid(Pid) and (L /= []) -> See operator precedence in the reference manual. > io:fwrite("it worked~n"); > > true -> > io:fwrite("it failed~n") > end. > > It prints out "it failed". If you change the 'and' to 'andalso' it works. > Cheers, Sebastien. From ayrnieu@REDACTED Thu Apr 5 13:15:35 2007 From: ayrnieu@REDACTED (Julian Fondren) Date: Thu, 5 Apr 2007 20:15:35 +0900 Subject: [erlang-questions] an erlang "gotcha" In-Reply-To: <200704052038.26904.als@iinet.net.au> References: <200704052038.26904.als@iinet.net.au> Message-ID: On 4/5/07, Anthony Shipman wrote: > Is there a place where difficulties with erlang and their solutions are > described? Perhaps another page at Trapexit. I don't know of one, but this series that I did while learning Mercury, http://community.livejournal.com/mercury_blog/2007/02/ really helped me; and I still think it a cool idea. I don't find Erlang's error messages formidable enough to repeat this, however, and Erlang errors -- as in your example -- would need to extend farther beyond static compilation errors than needed in Mercury. > Here's one that got me. > > It prints out "it failed". If you change the 'and' to 'andalso' it works. 1> { is_pid(self()), [1,2] /= [], if is_pid(self()) and [1,2] /= [] -> 1; true -> 2 end, if is_pid(self()) andalso [1,2] /= [] -> 1; true -> 2 end }. {true,true,2,1} 2> { is_pid(self()), [1,2] /= [], if is_pid(self()) and ([1,2] /= []) -> 1; true -> 2 end, if is_pid(self()) andalso ([1,2] /= []) -> 1; true -> 2 end }. {true,true,1,1} 3> is_pid(self()) and ([1,2] /= []). true 4> is_pid(self()) and [1,2] /= []. =ERROR REPORT==== 4-Apr-2007::15:38:44 === ... Odd. From erlang@REDACTED Thu Apr 5 13:18:16 2007 From: erlang@REDACTED (Peter Lund) Date: Thu, 05 Apr 2007 13:18:16 +0200 Subject: [erlang-questions] an erlang "gotcha" In-Reply-To: <200704052038.26904.als@iinet.net.au> References: <200704052038.26904.als@iinet.net.au> Message-ID: <4614DAF8.2080209@lundata.se> In your example 'and' is evaluated before '/=', so it tries to do 'is_pid(Pid) and L' first which fails since L is not boolean. It seems to go against normal intuition, that changing 'and' to 'andalso' makes it do '/=' before 'andalso'. Anyhow this is explained by the Operator Precedence list: http://erlang.org/doc/doc-5.5.4/doc/reference_manual/expressions.html#6.24 /Peter Anthony Shipman skrev: > Is there a place where difficulties with erlang and their solutions are > described? Perhaps another page at Trapexit. > > Here's one that got me. > > -module(g). > -export([run/0]). > > run() -> > Pid = spawn(fun() -> io:fwrite("spawned~n") end), > L = [1, 2, 3], > io:fwrite("Pid=~p L=~p~n", [Pid, L]), > if > is_pid(Pid) and L /= [] -> > io:fwrite("it worked~n"); > > true -> > io:fwrite("it failed~n") > end. > > It prints out "it failed". If you change the 'and' to 'andalso' it works. > > From serge@REDACTED Thu Apr 5 15:54:18 2007 From: serge@REDACTED (Serge Aleynikov) Date: Thu, 05 Apr 2007 08:54:18 -0500 Subject: [erlang-questions] http client and server: inets, ibrowse, yaws In-Reply-To: <4614B1D1.8030806@erix.ericsson.se> References: <4614B1D1.8030806@erix.ericsson.se> Message-ID: <4614FF8A.1060704@hq.idt.net> Ingela Anderton Andin wrote: >> Also I need to embed an simple HTTP server and got the same problem with >> using 'yaws' or inets 'httpd'. Furthermore I cannot figure out how to start >> httpd without config file or root directory ... yaws is simplest to embed. > > > This one is harder to answer. The intes httpd and yaws have different approaches > and both have their pros and cons. The Inets one is very old and inspired by apache. It also has a lot of legacy, that I would rather get rid of but that is impossible as we have customers that use it a lot. I think that yaws is also used a lot in the open source community and I can see things I like about it. > > There is no officially supported way to start inets > without a config file, although webtool does that. I would not really recommend using webtools > strategy as it might change without warning. It's in the plans for inets to improve start > strategies but I am not making any promises until when this will be ready. Being able to start inets by providing configuration options to the start function or from the application's environment in addition to the config file would definitely be a big plus. We've had quite a positive experience in using inets HTTP server. Not tried it for large sites, but we've successfully used it for internal AJAX client applications, extended it with custom modules, etc. Serge From lcoquelle@REDACTED Thu Apr 5 16:17:06 2007 From: lcoquelle@REDACTED (Ludovic Coquelle) Date: Thu, 5 Apr 2007 22:17:06 +0800 Subject: [erlang-questions] http client and server: inets, ibrowse, yaws In-Reply-To: <4614FF8A.1060704@hq.idt.net> References: <4614B1D1.8030806@erix.ericsson.se> <4614FF8A.1060704@hq.idt.net> Message-ID: Thanks for all the advices. Now I feel confident to use inets for http client. For the server side, I just need to embed a very very simple http server. My goal is to create an easy API to my application for any language. Thus I will probably use yaws because it is easy to embed and it may enable a future use of more sophisticated RPC (SOAP, JSON...). I would have used inets httpd if I could have find an easy way to start it without external config file. Thanks everybody! On 4/5/07, Serge Aleynikov wrote: > > Ingela Anderton Andin wrote: > >> Also I need to embed an simple HTTP server and got the same problem > with > >> using 'yaws' or inets 'httpd'. Furthermore I cannot figure out how to > start > >> httpd without config file or root directory ... yaws is simplest to > embed. > > > > > > This one is harder to answer. The intes httpd and yaws have different > approaches > > and both have their pros and cons. The Inets one is very old and > inspired by apache. It also has a lot of legacy, that I would rather get rid > of but that is impossible as we have customers that use it a lot. I think > that yaws is also used a lot in the open source community and I can see > things I like about it. > > > > There is no officially supported way to start inets > > without a config file, although webtool does that. I would not really > recommend using webtools > > strategy as it might change without warning. It's in the plans for inets > to improve start > > strategies but I am not making any promises until when this will be > ready. > > Being able to start inets by providing configuration options to the > start function or from the application's environment in addition to the > config file would definitely be a big plus. > > We've had quite a positive experience in using inets HTTP server. Not > tried it for large sites, but we've successfully used it for internal > AJAX client applications, extended it with custom modules, etc. > > Serge > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -------------- next part -------------- An HTML attachment was scrubbed... URL: From serge@REDACTED Fri Apr 6 01:28:52 2007 From: serge@REDACTED (Serge Aleynikov) Date: Thu, 05 Apr 2007 19:28:52 -0400 Subject: [erlang-questions] inets services startup Message-ID: <46158634.5000904@hq.idt.net> While accidentally entering wrong information in inets' server configuration file I got an error report stating that a child spec was not created. As a result the corresponding service didn't get started. Upon examining sources, I found the following code with exit({error,Reason}) commented out: httpd_sup.erl: ============== child_spec([], Acc) -> Acc; child_spec([{httpd, HttpdService} | Rest], Acc) -> NewHttpdService = mk_tuple_list(HttpdService), %% Acc2 = child_spec2(NewHttpdService,Acc), NewAcc= case catch child_spec2(NewHttpdService) of {ok,Acc2} -> [Acc2|Acc]; {error,Reason} -> error_msg("failed to create child spec for ~n~p~ndue to: ~p", [HttpdService,Reason]), % exit({error,Reason}) Acc end, child_spec(Rest,NewAcc). I was wondering what the authors had in mind by somewhat silently ignoring the critical error at startup. Wouldn't it be proper to uncomment that line? Serge -- Serge Aleynikov Routing R&D, IDT Telecom Tel: +1 (973) 438-3436 Fax: +1 (973) 438-1464 From fritchie@REDACTED Fri Apr 6 02:52:12 2007 From: fritchie@REDACTED (Scott Lystig Fritchie) Date: Thu, 05 Apr 2007 19:52:12 -0500 Subject: [erlang-questions] Two SNMP questions: SHA auth + authPriv, authenticationFailure trap Message-ID: <200704060052.l360qCjA067327@snookles.snookles.com> Greetings -- I've got a couple of SNMP-related questions. 1. Does anyone have an Erlang/OTP SNMP agent that can successfully handle the crypto required by 'authPriv' (either DES or AES) when using the SHA authentication method? If yes, then would you mind sending me a copy of a "usm.conf" entry that works? (Along with the clear-text passphrases :-) I'm trying to figure out if my SHA auth failures are due to a configuration problem, an OTP bug, or something else.(*) 2. Sorry, this is an SNMPv3 newbie question, but I'm anticipating a probably-going-to-be-asked question from our customer. If my Erlang/OTP SNMP agent receives an SNMPv3 query with a bad user name (a usmStatsUnknownUserNames error) or bad authentication passphrase (a usmStatsWrongDigests error), ... ... is my app supposed to be sending an authenticationFailure trap? I have snmpEnableAuthenTraps.0 set to enabled(1), but it isn't clear to me if the authenticationFailure is only for v1 or v2c auth errors or for all auth errors. -Scott (*) Yes, I've asked this question before. The problem I'm seeing is one where I get usmStatsDecryptionErrors errors when authenticating with a SHA digest. The privacy encryption method, DES or AES, doesn't matter. If I use MD5 auth with the same encryption method (either one), I have no problem. From serge@REDACTED Fri Apr 6 06:05:04 2007 From: serge@REDACTED (Serge) Date: Thu, 05 Apr 2007 23:05:04 -0500 Subject: [erlang-questions] inets services startup In-Reply-To: <46158634.5000904@hq.idt.net> References: <46158634.5000904@hq.idt.net> Message-ID: <4615C6F0.4070001@corp.idt.net> I've been trying to work around the inets startup issue described in the former email of failing to crash inets in case of a inability to start for a httpd service given its configuration file. I also need to run inets as an embedded application. The best solution I could come up with was not to use inets' own supervisor, but start a custom one, register it as 'httpd_sup' so that httpd_sup:start_child/1 could be used to link to this supervisor. Since httpd_sup:start_child/1 doesn't accept the supervisor name I am enforced to call this supervisor 'httpd_sup'. Are there any more elegant ways of embedding inets and solving the described issue aside from patching the distribution? What I would like to see implemented in inets is a function: httpd_sup:start_child(Supervisor, ConfigList) Supervisor = atom() % Name of a parent supervisor ConfigList = [{Option, Value}] % What's returned by httpd_conf:load/1 Serge -module(test_app). -behaviour(application). %% application callbacks -export([start/2, stop/1]). %% supervisor callbacks -export([init/1]). %%%------------------------------------------------------------------- %%% Callbacks functions from application %%%------------------------------------------------------------------- %%-------------------------------------------------------------------- %% @spec start(Type, StartArgs) -> Result %% Result = {ok, Pid} | %% {ok, Pid, State} | %% {error, Reason} %% @doc Start application callback %% @end %% @private %%-------------------------------------------------------------------- start(_Type, StartArgs) -> {ok, ConfigFile} = application:get_env(test_app, httpd_config_file), case supervisor:start_link({local, httpd_sup}, ?MODULE, []) of {ok, Pid} -> case catch httpd_sup:start_child(ConfigFile) of {ok, _Child} -> {ok, Pid}; {error,Error} -> {error, Error} end; {error, Error} -> {error, Error} end. %%-------------------------------------------------------------------- %% @spec stop(Reason) -> any %% @doc Stop application callback %% @end %% @private %%-------------------------------------------------------------------- stop(_Reason) -> ok. %%%------------------------------------------------------------------- %%% Callback functions from supervisor %%%------------------------------------------------------------------- %%%------------------------------------------------------------------- %%% Internal functions %%%------------------------------------------------------------------- init(_Args) -> {ok, {{one_for_one, 10, 3600}, []}}. Serge Aleynikov wrote: > While accidentally entering wrong information in inets' server > configuration file I got an error report stating that a child spec was > not created. As a result the corresponding service didn't get started. > > Upon examining sources, I found the following code with > exit({error,Reason}) commented out: > > httpd_sup.erl: > ============== > child_spec([], Acc) -> > Acc; > child_spec([{httpd, HttpdService} | Rest], Acc) -> > NewHttpdService = mk_tuple_list(HttpdService), > %% Acc2 = child_spec2(NewHttpdService,Acc), > NewAcc= > case catch child_spec2(NewHttpdService) of > {ok,Acc2} -> > [Acc2|Acc]; > {error,Reason} -> > error_msg("failed to create child spec for ~n~p~ndue to: ~p", > [HttpdService,Reason]), > % exit({error,Reason}) > Acc > end, > child_spec(Rest,NewAcc). > > I was wondering what the authors had in mind by somewhat silently > ignoring the critical error at startup. Wouldn't it be proper to > uncomment that line? > > Serge > From ayrnieu@REDACTED Fri Apr 6 08:47:51 2007 From: ayrnieu@REDACTED (Julian Fondren) Date: Fri, 6 Apr 2007 15:47:51 +0900 Subject: [erlang-questions] inets services startup In-Reply-To: <4615C6F0.4070001@corp.idt.net> References: <46158634.5000904@hq.idt.net> <4615C6F0.4070001@corp.idt.net> Message-ID: On 4/6/07, Serge wrote: > Are there any more elegant ways of embedding inets and > solving the described issue aside from patching the distribution? Why do you discard the solution of patching the distribution? It's quite easy to do; you can even have your patched module refuse to operate when other modules of its OTP application change versions, as in a OTP upgrade. Your patched module can live in its own space and just get loaded favorably with code:add_patha/1 Cheers, Julian From goertzen@REDACTED Fri Apr 6 13:49:22 2007 From: goertzen@REDACTED (Daniel Goertzen) Date: Fri, 06 Apr 2007 06:49:22 -0500 Subject: [erlang-questions] inets services startup In-Reply-To: <4615C6F0.4070001@corp.idt.net> References: <46158634.5000904@hq.idt.net> <4615C6F0.4070001@corp.idt.net> Message-ID: <461633C2.1050208@ertw.com> We've used linux FUSE with great success to integrate a number of 3rd party apps in an embedded system. Whenever one of those apps reads a config file, our FUSE code generates the config on the fly. Mind you, this was all in C++, but there is some work being done on an erlang binding for FUSE: http://www.erlang.org/pipermail/erlang-questions/2007-January/025055.html I don't know if this would solve all your problem... and it would force you to use linux. Dan. Serge wrote: > I've been trying to work around the inets startup issue described in the > former email of failing to crash inets in case of a inability to start > for a httpd service given its configuration file. I also need to run > inets as an embedded application. The best solution I could come up > with was not to use inets' own supervisor, but start a custom one, > register it as 'httpd_sup' so that httpd_sup:start_child/1 could be used > to link to this supervisor. Since httpd_sup:start_child/1 doesn't > accept the supervisor name I am enforced to call this supervisor > 'httpd_sup'. Are there any more elegant ways of embedding inets and > solving the described issue aside from patching the distribution? > > What I would like to see implemented in inets is a function: > > httpd_sup:start_child(Supervisor, ConfigList) > Supervisor = atom() % Name of a parent supervisor > ConfigList = [{Option, Value}] % What's returned by httpd_conf:load/1 > > Serge > > > -module(test_app). > -behaviour(application). > > %% application callbacks > -export([start/2, stop/1]). > > %% supervisor callbacks > -export([init/1]). > > %%%------------------------------------------------------------------- > %%% Callbacks functions from application > %%%------------------------------------------------------------------- > > %%-------------------------------------------------------------------- > %% @spec start(Type, StartArgs) -> Result > %% Result = {ok, Pid} | > %% {ok, Pid, State} | > %% {error, Reason} > %% @doc Start application callback > %% @end > %% @private > %%-------------------------------------------------------------------- > start(_Type, StartArgs) -> > {ok, ConfigFile} = application:get_env(test_app, httpd_config_file), > case supervisor:start_link({local, httpd_sup}, ?MODULE, []) of > {ok, Pid} -> > case catch httpd_sup:start_child(ConfigFile) of > {ok, _Child} -> > {ok, Pid}; > {error,Error} -> > {error, Error} > end; > {error, Error} -> > {error, Error} > end. > > %%-------------------------------------------------------------------- > %% @spec stop(Reason) -> any > %% @doc Stop application callback > %% @end > %% @private > %%-------------------------------------------------------------------- > stop(_Reason) -> > ok. > > %%%------------------------------------------------------------------- > %%% Callback functions from supervisor > %%%------------------------------------------------------------------- > > %%%------------------------------------------------------------------- > %%% Internal functions > %%%------------------------------------------------------------------- > > init(_Args) -> > {ok, {{one_for_one, 10, 3600}, []}}. > > > Serge Aleynikov wrote: > >> While accidentally entering wrong information in inets' server >> configuration file I got an error report stating that a child spec was >> not created. As a result the corresponding service didn't get started. >> >> Upon examining sources, I found the following code with >> exit({error,Reason}) commented out: >> >> httpd_sup.erl: >> ============== >> child_spec([], Acc) -> >> Acc; >> child_spec([{httpd, HttpdService} | Rest], Acc) -> >> NewHttpdService = mk_tuple_list(HttpdService), >> %% Acc2 = child_spec2(NewHttpdService,Acc), >> NewAcc= >> case catch child_spec2(NewHttpdService) of >> {ok,Acc2} -> >> [Acc2|Acc]; >> {error,Reason} -> >> error_msg("failed to create child spec for ~n~p~ndue to: ~p", >> [HttpdService,Reason]), >> % exit({error,Reason}) >> Acc >> end, >> child_spec(Rest,NewAcc). >> >> I was wondering what the authors had in mind by somewhat silently >> ignoring the critical error at startup. Wouldn't it be proper to >> uncomment that line? >> >> Serge >> >> > > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > > > From serge@REDACTED Fri Apr 6 15:08:00 2007 From: serge@REDACTED (Serge Aleynikov) Date: Fri, 06 Apr 2007 08:08:00 -0500 Subject: [erlang-questions] inets services startup In-Reply-To: <461633C2.1050208@ertw.com> References: <46158634.5000904@hq.idt.net> <4615C6F0.4070001@corp.idt.net> <461633C2.1050208@ertw.com> Message-ID: <46164630.6070507@hq.idt.net> Dan, I can see how your suggestion can work well for some special cases, but I am not sure how it can help when you have a bad/missing value in the inets configuration that would cause one of the inets services to fail starting without crashing inets. The later is the problem I am having as I don't want to see inets application being started if httpd service cannot come up given its configuration. The fact that it requires a separate config file is merely an inconvenience I can live with. Serge Daniel Goertzen wrote: > We've used linux FUSE with great success to integrate a number of 3rd > party apps in an embedded system. Whenever one of those apps reads a > config file, our FUSE code generates the config on the fly. > > Mind you, this was all in C++, but there is some work being done on an > erlang binding for FUSE: > http://www.erlang.org/pipermail/erlang-questions/2007-January/025055.html > > I don't know if this would solve all your problem... and it would force > you to use linux. > > Dan. > > Serge wrote: >> I've been trying to work around the inets startup issue described in the >> former email of failing to crash inets in case of a inability to start >> for a httpd service given its configuration file. I also need to run >> inets as an embedded application. The best solution I could come up >> with was not to use inets' own supervisor, but start a custom one, >> register it as 'httpd_sup' so that httpd_sup:start_child/1 could be used >> to link to this supervisor. Since httpd_sup:start_child/1 doesn't >> accept the supervisor name I am enforced to call this supervisor >> 'httpd_sup'. Are there any more elegant ways of embedding inets and >> solving the described issue aside from patching the distribution? >> >> What I would like to see implemented in inets is a function: >> >> httpd_sup:start_child(Supervisor, ConfigList) >> Supervisor = atom() % Name of a parent supervisor >> ConfigList = [{Option, Value}] % What's returned by httpd_conf:load/1 >> >> Serge >> >> >> -module(test_app). >> -behaviour(application). >> >> %% application callbacks >> -export([start/2, stop/1]). >> >> %% supervisor callbacks >> -export([init/1]). >> >> %%%------------------------------------------------------------------- >> %%% Callbacks functions from application >> %%%------------------------------------------------------------------- >> >> %%-------------------------------------------------------------------- >> %% @spec start(Type, StartArgs) -> Result >> %% Result = {ok, Pid} | >> %% {ok, Pid, State} | >> %% {error, Reason} >> %% @doc Start application callback >> %% @end >> %% @private >> %%-------------------------------------------------------------------- >> start(_Type, StartArgs) -> >> {ok, ConfigFile} = application:get_env(test_app, httpd_config_file), >> case supervisor:start_link({local, httpd_sup}, ?MODULE, []) of >> {ok, Pid} -> >> case catch httpd_sup:start_child(ConfigFile) of >> {ok, _Child} -> >> {ok, Pid}; >> {error,Error} -> >> {error, Error} >> end; >> {error, Error} -> >> {error, Error} >> end. >> >> %%-------------------------------------------------------------------- >> %% @spec stop(Reason) -> any >> %% @doc Stop application callback >> %% @end >> %% @private >> %%-------------------------------------------------------------------- >> stop(_Reason) -> >> ok. >> >> %%%------------------------------------------------------------------- >> %%% Callback functions from supervisor >> %%%------------------------------------------------------------------- >> >> %%%------------------------------------------------------------------- >> %%% Internal functions >> %%%------------------------------------------------------------------- >> >> init(_Args) -> >> {ok, {{one_for_one, 10, 3600}, []}}. >> >> >> Serge Aleynikov wrote: >> >>> While accidentally entering wrong information in inets' server >>> configuration file I got an error report stating that a child spec was >>> not created. As a result the corresponding service didn't get started. >>> >>> Upon examining sources, I found the following code with >>> exit({error,Reason}) commented out: >>> >>> httpd_sup.erl: >>> ============== >>> child_spec([], Acc) -> >>> Acc; >>> child_spec([{httpd, HttpdService} | Rest], Acc) -> >>> NewHttpdService = mk_tuple_list(HttpdService), >>> %% Acc2 = child_spec2(NewHttpdService,Acc), >>> NewAcc= >>> case catch child_spec2(NewHttpdService) of >>> {ok,Acc2} -> >>> [Acc2|Acc]; >>> {error,Reason} -> >>> error_msg("failed to create child spec for ~n~p~ndue to: ~p", >>> [HttpdService,Reason]), >>> % exit({error,Reason}) >>> Acc >>> end, >>> child_spec(Rest,NewAcc). >>> >>> I was wondering what the authors had in mind by somewhat silently >>> ignoring the critical error at startup. Wouldn't it be proper to >>> uncomment that line? >>> >>> Serge From serge@REDACTED Fri Apr 6 15:16:36 2007 From: serge@REDACTED (Serge Aleynikov) Date: Fri, 06 Apr 2007 08:16:36 -0500 Subject: [erlang-questions] inets services startup In-Reply-To: References: <46158634.5000904@hq.idt.net> <4615C6F0.4070001@corp.idt.net> Message-ID: <46164834.7050905@hq.idt.net> Julian Fondren wrote: > On 4/6/07, Serge wrote: >> Are there any more elegant ways of embedding inets and >> solving the described issue aside from patching the distribution? > > Why do you discard the solution of patching the distribution? > It's quite easy to do; you can even have your patched module > refuse to operate when other modules of its OTP application > change versions, as in a OTP upgrade. Your patched module > can live in its own space and just get loaded favorably with > code:add_patha/1 Frankly I already have far too many OTP matches to deal with. Every time there's a new OTP version released it becomes time consuming to analyze changes and merge. In fact I am very glad that the OTP team recently accepted our inet driver patches for SCTP support included in R11B-4 - those were the most painful patches to maintain outside of the OTP. The problem described in my last email sounds more like a flaw in inets functionality that likely needs to be fixed. I may submit a patch but if there is a workaround I am inclined to use the later. Serge From casper2000a@REDACTED Fri Apr 6 14:15:09 2007 From: casper2000a@REDACTED (Eranga Udesh) Date: Fri, 6 Apr 2007 17:45:09 +0530 Subject: [erlang-questions] R11B-2 SMP + HiPE: not loading native code In-Reply-To: <459C53CC.10004@hq.idt.net> Message-ID: <20070406121525.0133A19DC27C@mail.wavenet.lk> Use command as, "erlc -smp +native test.erl" It'll compile your code using SMP BEAM. - Eranga -----Original Message----- From: erlang-questions-bounces@REDACTED [mailto:erlang-questions-bounces@REDACTED] On Behalf Of Serge Aleynikov Sent: Thursday, January 04, 2007 6:40 AM To: Kostis Sagonas Cc: Dmitriy Kargapolov; erlang-questions@REDACTED Subject: Re: [erlang-questions] R11B-2 SMP + HiPE: not loading native code Is there any way to hint erlc (via command line) to use SMP-enabled beam? I was only able to do it like this: $ export ERLC_EMULATOR="erl -smp" $ erlc +native test.erl whereas "erlc +smp +native test.erl" doesn't use the SMP BEAM. Serge Kostis Sagonas wrote: > Dmitriy Kargapolov wrote: >> Hi, >> When loading natively compiled code (+native) in R11B-2 emulator running >> in SMP mode (-smp) I'm getting the following warning: >> >> =INFO REPORT==== 3-Jan-2007::18:53:24 === >> Warning: not loading native code for module test: it >> was compiled for an incompatible runtime system >> >> Does this mean HiPE and SMP could not be used together? > > It simply means that, unlike BEAM code, there is a dependency between > the native code generated using some runtime system and the runtime > system on which the code is actually run. > > Put differently, it just means that you have to re-generate the native > code using the SMP-enabled system, not generate it using the "standard" > one and then try to use it in the SMP one. > > Kostis > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > -- Serge Aleynikov Routing R&D, IDT Telecom Tel: +1 (973) 438-3436 Fax: +1 (973) 438-1464 _______________________________________________ erlang-questions mailing list erlang-questions@REDACTED http://www.erlang.org/mailman/listinfo/erlang-questions From mogorman@REDACTED Fri Apr 6 15:28:28 2007 From: mogorman@REDACTED (Matthew O'Gorman) Date: Fri, 6 Apr 2007 08:28:28 -0500 Subject: [erlang-questions] inets services startup In-Reply-To: <46164834.7050905@hq.idt.net> References: <46158634.5000904@hq.idt.net> <4615C6F0.4070001@corp.idt.net> <46164834.7050905@hq.idt.net> Message-ID: if only there were a public svn repo for people to maintain their own branches of the code and get constant updates.... maybe this wouldn't be as big of a problem. mog On 4/6/07, Serge Aleynikov wrote: > Julian Fondren wrote: > > On 4/6/07, Serge wrote: > >> Are there any more elegant ways of embedding inets and > >> solving the described issue aside from patching the distribution? > > > > Why do you discard the solution of patching the distribution? > > It's quite easy to do; you can even have your patched module > > refuse to operate when other modules of its OTP application > > change versions, as in a OTP upgrade. Your patched module > > can live in its own space and just get loaded favorably with > > code:add_patha/1 > > Frankly I already have far too many OTP matches to deal with. Every > time there's a new OTP version released it becomes time consuming to > analyze changes and merge. In fact I am very glad that the OTP team > recently accepted our inet driver patches for SCTP support included in > R11B-4 - those were the most painful patches to maintain outside of the OTP. > > The problem described in my last email sounds more like a flaw in inets > functionality that likely needs to be fixed. I may submit a patch but > if there is a workaround I am inclined to use the later. > > Serge > _______________________________________________ > erlang-questions mailing list > erlang-questions@REDACTED > http://www.erlang.org/mailman/listinfo/erlang-questions > From juneaftn@REDACTED Sat Apr 7 05:43:52 2007 From: juneaftn@REDACTED (June Kim) Date: Sat, 7 Apr 2007 12:43:52 +0900 Subject: [erlang-questions] eunit Message-ID: <6f80c1520704062043t7f034c33y9c5d272e39cdf94@mail.gmail.com> Hello, I downloaded eunit from cean. There isn't too much documentation for eunit at the moment. I know its basic usages but there seems to be much more functionality in eunit than those. For example, what are the file/code_monitors for? Are they for external use or not? From juneaftn@REDACTED Sat Apr 7 05:58:43 2007 From: juneaftn@REDACTED (June Kim) Date: Sat, 7 Apr 2007 12:58:43 +0900 Subject: [erlang-questions] copy or reference? Message-ID: <6f80c1520704062058s37341585pdb6778a83b767db2@mail.gmail.com> Hello, It looks like there are copy operations in some functional data structures in Erlang. Say, I have a list L and I want to update the n-th element in L. Then, a copy would happen, and it is an expensive operation, memory-wise and time-wise. What data structures and their operations in Erlang occur non-copy operations? From thomasl_erlang@REDACTED Sat Apr 7 12:07:35 2007 From: thomasl_erlang@REDACTED (Thomas Lindgren) Date: Sat, 7 Apr 2007 03:07:35 -0700 (PDT) Subject: [erlang-questions] copy or reference? In-Reply-To: <6f80c1520704062058s37341585pdb6778a83b767db2@mail.gmail.com> Message-ID: <32977.35246.qm@web38810.mail.mud.yahoo.com> --- June Kim wrote: > Hello, > > It looks like there are copy operations in some > functional data > structures in Erlang. Say, I have a list L and I > want to update the > n-th element in L. Then, a copy would happen, and it > is an expensive > operation, memory-wise and time-wise. To be precise, there is usually no copying as such; instead you build an updated version of the data structure. If you trace the execution by hand, I think you will see that there is no OO-style "deep copying" going on when you are replacing the Nth element of a list. Instead, the old and new version of the data structure will share parts. For example, when you replace the n:th element of a list x1,...xn....xm, you will normally build only new list cells x1',...,xn' but will still share xn+1...xm from the old list, and also share all the contents of the list. This is done routinely and safely precisely because the list and its elements cannot be destructively updated. If you find yourself repeatedly walking a list and replacing elements, you may still get an unpleasant algorithmic complexity (as can happen for list algorithms). In that case, you should first of all change your algorithm or your data structure. Perform several updates at once, for example, or use a tree instead of a list. Or rethink your algorithm. > What data structures and their operations in Erlang > occur non-copy operations? If you still need destructive updates, first look at ets tables or mnesia. I would recommend reading up on non-list data structures as well, such as dict or gb_trees. If you are worrying about low-level performance rather than algorithmic performance, then I suggest you also read the following part of the Erlang manual. http://www.erlang.org/doc/doc-5.5.4/doc/efficiency_guide/part_frame.html Best, Thomas ____________________________________________________________________________________ Finding fabulous fares is fun. Let Yahoo! FareChase search your favorite travel sites to find flight and hotel bargains. http://farechase.yahoo.com/promo-generic-14795097 From richardc@REDACTED Sat Apr 7 12:09:42 2007 From: richardc@REDACTED (Richard Carlsson) Date: Sat, 07 Apr 2007 12:09:42 +0200 Subject: [erlang-questions] eunit In-Reply-To: <6f80c1520704062043t7f034c33y9c5d272e39cdf94@mail.gmail.com> References: <6f80c1520704062043t7f034c33y9c5d272e39cdf94@mail.gmail.com> Message-ID: <46176DE6.1050606@it.uu.se> June Kim wrote: > Hello, > > I downloaded eunit from cean. > > There isn't too much documentation for eunit at the moment. I know its > basic usages but there seems to be much more functionality in eunit > than those. I' currently working on a "proper beta" release with better documentation. There are some technical things I want to fix before the release, but it shouldn't be long now. Sadly, I had no time to work on eunit for the last six months, so there was very little that happened after the alpha release. Stay tuned. > For example, what are the file/code_monitors for? Are they for > external use or not? They're experimental for now, not officially documented, and might be moved to a separate package. The code monitor is used for some preliminary auto-testing functionality in eunit. /Richard From richardc@REDACTED Sat Apr 7 12:44:22 2007 From: richardc@REDACTED (Richard Carlsson) Date: Sat, 07 Apr 2007 12:44:22 +0200 Subject: [erlang-questions] copy or reference? In-Reply-To: <6f80c1520704062058s37341585pdb6778a83b767db2@mail.gmail.com> References: <6f80c1520704062058s37341585pdb6778a83b767db2@mail.gmail.com> Message-ID: <46177606.5030604@it.uu.se> June Kim wrote: > It looks like there are copy operations in some functional data > structures in Erlang. Say, I have a list L and I want to update the > n-th element in L. Then, a copy would happen, and it is an expensive > operation, memory-wise and time-wise. > > What data structures and their operations in Erlang occur non-copy > operations? It's usually not copying that happens, but rewriting. (Real copying only happens when you send a message from one process to another, at least when the processes are on different machines.) For example, say you have a list L0 = ["a","b","c","d","e"]. You want to change the third element to "x". To do this, you traverse the list recursively until you find the sublist ["c","d","e"]. The head element of this is "c", and the tail is T0=["d","e"]. You then rewrite this to T1 = ["x" | T0], which _reuses_ the sublist ["d","e"] (it just copies a pointer to the list). After that, you return from the recursive calls, first creating T2 = ["b" | T1] (this also only copies a pointer to "b"), and then creating L1 = ["a" | T2]. It's important to realise that the original list is not changed. L0 is still ["a","b","c","d","e"], but it now shares the tail part T0=["d","e"] with the new list L1=["a","b","x","d","e"]. The above might sound like a lot of work, but it only created 3 new list cells (each using only 2 words), and list cell creation is a very cheap operation (compared to object creation in typical OO languages). When the original list L0 has no more references that point to it, those parts that are not shared with other data structures will be garbage collected (in this case, the part ["a", "b" | _]). The reasoning above also applies for tuples; you can see a list cell as a special kind of tuple (or vice versa), so rewriting tree structures built out of tuples will only create new tuples with pointers to mostly the same old data - it will not copy data. /Richard From juneaftn@REDACTED Sat Apr 7 15:18:59 2007 From: juneaftn@REDACTED (June Kim) Date: Sat, 7 Apr 2007 22:18:59 +0900 Subject: [erlang-questions] speeding up 3N+1 Message-ID: <6f80c1520704070618lcf438pd9b9f42cf4b4686c@mail.gmail.com> Hello, First of all, please keep in mind that I am a newbie in Erlang. (sorry if the codes annoy you) Please have a look at this famous problem. http://acm.uva.es/p/v1/100.html The input number can be upto 1,000,000. (let's just suppose 1 million is included, even though the problem states the maximal input is less than 1 million) Let's see the worst case(when the start/end pair is {1, 1000000}) time performance of the program. Following is a trial at solving this problem: -module(tnp1_process_dict). -compile(export_all). cycle(1) -> 1; cycle(N) -> case get(N) of undefined -> SN = if N rem 2 =:= 0 -> 1 + cycle(N div 2); true -> 2 + cycle((3 * N + 1) div 2) end, put(N, SN), SN; Cached -> Cached end. max(A, B) -> lists:max(lists:map(fun cycle/1, lists:seq(A, B))). Actually, it's from a friend of mine, who is also in the same Erlang community(we are all just novices though) with me. It's quite effiecient. 1> timer:tc(tnp1_process_dict,max,[1,1000000]). {2547000,525} Less than 3 seconds on my sluggish machine. Good. However, I didn't quite like the solution. It uses the process dictionary. From reading Erlang books and manuals, I thought the process dictionary should be the last resort for this kind of usage. I thought I could deal the problem without using the process dictionary, without trading off the speed. Following is my trial: -module(tnp1_functional). -compile(export_all). newCache()-> dict:from_list([{1,1}]). store(K,V,Cache)-> dict:store(K,V,Cache). find(K,Cache)-> dict:find(K,Cache). nn(N) when N rem 2 =:= 0 -> N div 2; nn(N) -> 3*N+1. update([],_,Cache)-> Cache; update([H|ToStore],V,Cache)-> Cache2=store(H,V+1,Cache), update(ToStore,V+1,Cache2). cl(N,Cnt,Cache,ToStore)-> case find(N,Cache) of {ok,V} -> Cache2=update(ToStore,V,Cache), {Cnt+V,Cache2}; error -> cl(nn(N),Cnt+1,Cache,[N|ToStore]) end. maxcl(From,To,Cache,Max) when From>To -> {Max,Cache}; maxcl(From,To,Cache,Max)-> {Cl,Cache2}=cl(From,0,Cache,[]), maxcl(From+1,To,Cache2,lists:max([Cl,Max])). maxcl(From,To)-> Cache=newCache(), maxcl(From,To,Cache,1). max(From,To)-> {V,_}=maxcl(From,To), V. It's much longer. And much slower; I'd say excruciatingly. 1> timer:tc(tnp1_functional,max,[1,100000]). {7953000,351} See? It's 100,000, not one million, even. When I ran it with one million, it didn't end at least in a couple of minutes. Maybe my choice of using dict is wrong? Could ets be substantially better? Or my approach totally wrong? I don't know yet. (I'll experiment with other data structures and approaches, though) Okay, that's it. I would appreciate any suggestions for improvement. June From juneaftn@REDACTED Sat Apr 7 15:57:14 2007 From: juneaftn@REDACTED (June Kim) Date: Sat, 7 Apr 2007 22:57:14 +0900 Subject: [erlang-questions] speeding up 3N+1 In-Reply-To: <6f80c1520704070618lcf438pd9b9f42cf4b4686c@mail.gmail.com> References: <6f80c1520704070618lcf438pd9b9f42cf4b4686c@mail.gmail.com> Message-ID: <6f80c1520704070657v6d389a54l7d38798d3b0de189@mail.gmail.com> Well, I tried it with ets: Replace the three cache functions with the following: newCache()-> Cache=ets:new(test,[set]), ets:insert(Cache,{1,1}), Cache. store(K,V,Cache)-> ets:insert(Cache,{K,V}), Cache. find(K,Cache)-> case ets:lookup(Cache,K) of [] -> error; [{K,V}] -> {ok,V} end. Now max(1,100000) takes about 0.9 secs, and max(1,1000000) takes about 10 secs. Exploiting the trick in the process dictionary version(when N is odd, 3N+1 is even), for one million, it reduces to about 8 secs. It's a huge improvement, but still inferior to the process dictionary version. Moreover, ets isn't functional data structure(with side-effects). So the process dictionary is the king? 2007/4/7, June Kim : > Hello, > > First of all, please keep in mind that I am a newbie in Erlang. (sorry > if the codes annoy you) > > Please have a look at this famous problem. http://acm.uva.es/p/v1/100.html > > The input number can be upto 1,000,000. (let's just suppose 1 million > is included, even though the problem states the maximal input is less > than 1 million) Let's see the worst case(when the start/end pair is > {1, 1000000}) time performance of the program. > > Following is a trial at solving this problem: > > -module(tnp1_process_dict). > -compile(export_all). > > cycle(1) -> > 1; > cycle(N) -> > case get(N) of > undefined -> > SN = if > N rem 2 =:= 0 -> > 1 + cycle(N div 2); > true -> > 2 + cycle((3 * N + 1) div 2) > end, > put(N, SN), > SN; > Cached -> > Cached > end. > > max(A, B) -> > lists:max(lists:map(fun cycle/1, lists:seq(A, B))). > > Actually, it's from a friend of mine, who is also in the same Erlang > community(we are all just novices though) with me. It's quite > effiecient. > > 1> timer:tc(tnp1_process_dict,max,[1,1000000]). > {2547000,525} > > Less than 3 seconds on my sluggish machine. Good. > > However, I didn't quite like the solution. It uses the process > dictionary. From reading Erlang books and manuals, I thought the > process dictionary should be the last resort for this kind of usage. I > thought I could deal the problem without using the process dictionary, > without trading off the speed. > > Following is my trial: > > -module(tnp1_functional). > -compile(export_all). > > newCache()-> > dict:from_list([{1,1}]). > store(K,V,Cache)-> > dict:store(K,V,Cache). > find(K,Cache)-> > dict:find(K,Cache). > > nn(N) when N rem 2 =:= 0 -> > N div 2; > nn(N) -> > 3*N+1. > > update([],_,Cache)-> > Cache; > update([H|ToStore],V,Cache)-> > Cache2=store(H,V+1,Cache), > update(ToStore,V+1,Cache2). > > cl(N,Cnt,Cache,ToStore)-> > case find(N,Cache) of > {ok,V} -> > Cache2=update(ToStore,V,Cache), > {Cnt+V,Cache2}; > error -> > cl(nn(N),Cnt+1,Cache,[N|ToStore]) > end. > > maxcl(From,To,Cache,Max) when From>To -> > {Max,Cache}; > maxcl(From,To,Cache,Max)-> > {Cl,Cache2}=cl(From,0,Cache,[]), > maxcl(From+1,To,Cache2,lists:max([Cl,Max])). > > maxcl(From,To)-> > Cache=newCache(), > maxcl(From,To,Cache,1). > > max(From,To)-> > {V,_}=maxcl(From,To), > V. > > It's much longer. And much slower; I'd say excruciatingly. > > 1> timer:tc(tnp1_functional,max,[1,100000]). > {7953000,351} > > See? It's 100,000, not one million, even. When I ran it with one > million, it didn't end at least in a couple of minutes. > > Maybe my choice of using dict is wrong? Could ets be substantially > better? Or my approach totally wrong? I don't know yet. (I'll > experiment with other data structures and approaches, though) > > Okay, that's it. I would appreciate any suggestions for improvement. > > June > From vances@REDACTED Sat Apr 7 16:33:32 2007 From: vances@REDACTED (Vance Shipley) Date: Sat, 7 Apr 2007 10:33:32 -0400 Subject: [erlang-questions] speeding up 3N+1 In-Reply-To: <6f80c1520704070618lcf438pd9b9f42cf4b4686c@mail.gmail.com> References: <6f80c1520704070618lcf438pd9b9f42cf4b4686c@mail.gmail.com> Message-ID: <20070407143332.GA72359@frogman.motivity.ca> On Sat, Apr 07, 2007 at 10:18:59PM +0900, June Kim wrote: } Please have a look at this famous problem. http://acm.uva.es/p/v1/100.html June, In functional programming you pass arguments instead of using global variables. -module(threeNplus1). -export([do/1]). do(1) -> io:fwrite(" 1~n"); do(N) when N rem 2 /= 0 -> io:fwrite(" ~b", [N]), do(3 * N + 1); do(N) -> io:fwrite(" ~b", [N]), do(N div 2). 1> threeNplus1:do(22). 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 ok } cycle(1) -> } 1; } cycle(N) -> } case get(N) of } undefined -> } SN = if } N rem 2 =:= 0 -> } 1 + cycle(N div 2); } true -> } 2 + cycle((3 * N + 1) div 2) } end, } put(N, SN), } SN; } Cached -> } Cached } end. The really big problem above is in tail recursion. You don't want to have to wait for the answer to cycle(N div 2) before knowing the answer to cycle(N). -Vance From juneaftn@REDACTED Sat Apr 7 16:55:38 2007 From: juneaftn@REDACTED (June Kim) Date: Sat, 7 Apr 2007 23:55:38 +0900 Subject: [erlang-questions] speeding up 3N+1 In-Reply-To: <20070407143332.GA72359@frogman.motivity.ca> References: <6f80c1520704070618lcf438pd9b9f42cf4b4686c@mail.gmail.com> <20070407143332.GA72359@frogman.motivity.ca> Message-ID: <6f80c1520704070755y1cfbe245g8a36b603cd08b0ea@mail.gmail.com> 2007/4/7, Vance Shipley : > On Sat, Apr 07, 2007 at 10:18:59PM +0900, June Kim wrote: > } Please have a look at this famous problem. http://acm.uva.es/p/v1/100.html > > June, > > In functional programming you pass arguments instead of using > global variables. > > -module(threeNplus1). > -export([do/1]). > > do(1) -> > io:fwrite(" 1~n"); > do(N) when N rem 2 /= 0 -> > io:fwrite(" ~b", [N]), > do(3 * N + 1); > do(N) -> > io:fwrite(" ~b", [N]), > do(N div 2). > > 1> threeNplus1:do(22). > 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 > ok > > } cycle(1) -> > } 1; > } cycle(N) -> > } case get(N) of > } undefined -> > } SN = if > } N rem 2 =:= 0 -> > } 1 + cycle(N div 2); > } true -> > } 2 + cycle((3 * N + 1) div 2) > } end, > } put(N, SN), > } SN; > } Cached -> > } Cached > } end. > > The really big problem above is in tail recursion. You don't > want to have to wait for the answer to cycle(N div 2) before > knowing the answer to cycle(N). > > -Vance > > Yes. I am well aware of those issues. (the code isn't mine, but from a friend of mine who's into functional programming for the first time with Erlang -- I have programmed in other FP languages before) His code uses global variable(process dictionary) and not tail-recursive. However, it's the fastest. (even in a "functional programming" language -- ironic, isn't it?) My version using dict, which is also included in my original posting(I don't think you have seen it yet), is tail-recursive and functional, but slow. I did some experimentations. %% /