From per@REDACTED Mon Jun 1 00:29:07 2009 From: per@REDACTED (Per Hedeland) Date: Mon, 1 Jun 2009 00:29:07 +0200 (CEST) Subject: [erlang-questions] Multi-precision math, random number generator entropy, various other questions In-Reply-To: Message-ID: <200905312229.n4VMT7dd005528@pluto.hedeland.org> Will wrote: > >On Sun, May 31, 2009 at 2:04 PM, Per Hedeland wrote: >> >> But anyway, I think the best answer was already given - use >> crypto:rand_bytes/1 if you really need "crypto quality" random numbers. >> The OpenSSL crypto library will use /dev/urandom and the like (depending >> on availability) to seed a high-quality PRNG - i.e. you get something >> that is a) portable and b) probably the best quality you *can* get on a >> given OS/HW. > >FYI, crypto:rand_bytes/1 calls OpenSSL's RAND_pseudo_bytes() function. > > http://openssl.org/docs/crypto/RAND_bytes.html. > >The Description section of the man page indicates that the output is not >cryptographically strong. It says "not necessarily", and in that context > However the Return Values section says the >output is strong when the return value is 1. makes sense. I.e. basically they do the same thing, just that RAND_bytes() "fails" if it can't provide cryptographically strong numbers, RAND_pseudo_bytes() doesn't fail, just returns 1 anyway.:-) (See the source for the default implementation of RAND_pseudo_bytes() below.) And this is similar to the difference between /dev/random and /dev/urandom on systems where there is a difference - you can use /dev/random if you absolutely must have "real" entropy, but be prepared to wait forever.:-) Of course an interactive key-generating program has other options, like aborting with an error message or asking the user to do some random typing for a while, but a "system daemon" will generally just have to make do with what it can get. --Per crypto/rand/md_rand.c: ret = RAND_bytes(buf, num); if (ret == 0) { err = ERR_peek_error(); if (ERR_GET_LIB(err) == ERR_LIB_RAND && ERR_GET_REASON(err) == RAND_R_PRNG_NOT_SEEDED) ERR_clear_error(); } return (ret); From bflatmaj7th@REDACTED Mon Jun 1 00:49:34 2009 From: bflatmaj7th@REDACTED (Richard Andrews) Date: Mon, 1 Jun 2009 08:49:34 +1000 Subject: [erlang-questions] RNG seeding example from YAWS In-Reply-To: References: Message-ID: <7702c0610905311549n36c25512mabcb8fa0e676966f@mail.gmail.com> > So given this example, would a process' seeding using random:seed() > affect any other running processes, or just the current process where > the seed was changed? ?i.e. if there were 100 processes spawned, each of > which initially changes the random seed, would that seed only affect and > be used in conjunction with random:uniform() called from within that > current process? Given that the entropy is held in the state object and erlang processes do not share state I think there can be only one conclusion. From rvirding@REDACTED Mon Jun 1 02:29:33 2009 From: rvirding@REDACTED (Robert Virding) Date: Mon, 1 Jun 2009 02:29:33 +0200 Subject: [erlang-questions] Multi-precision math, random number generator entropy, various other questions In-Reply-To: References: Message-ID: <3dbc6d1c0905311729r345bf0b5i583a9a54fd6affb7@mail.gmail.com> Hi Greg, 2009/5/31 Greg Perry > I am not a crypto expert, but it seems to me that just choosing a strong > random seed value is insufficient -- the heart of the problem is that the > RNG algorithm is simply not designed to generate cryptographically strong > random numbers. If you want strong random number generation use the crypto > module -- it pulls from /dev/urandom and various other entropy sources via > OpenSSL. I can most definitely say that the RNG algorithm in the module random does not generate cryptographically sound random numbers. It is a perfectly reasonable RNG for simulations and things like that but not for serious cryptography. Unfortunately the documentation does not mention this. Robert From erlang@REDACTED Mon Jun 1 09:26:15 2009 From: erlang@REDACTED (Joe Armstrong) Date: Mon, 1 Jun 2009 09:26:15 +0200 Subject: [erlang-questions] Breaking out of a foldl In-Reply-To: <4A215C77.2010606@erlang-consulting.com> References: <1c3be50f0905290916r11734dc5k820e86be80f737fe@mail.gmail.com> <14F8BA751CA44C5B8A886C6143BE29BE@SSI.CORP> <4A215C77.2010606@erlang-consulting.com> Message-ID: <9b08084c0906010026r23a245bcy23f586ccbe289696@mail.gmail.com> On Sat, May 30, 2009 at 6:19 PM, Mazen Harake wrote: > Because it is a hack? > > a "fold_until" would be much smoother. Uuugh - smoothness????????????? Why have two functions when one (the existing foldl) is perfectly adequate? The use of throw to abnormally terminate a recursion is not a hack. That is what catch-throw was designed to do. exit/1 is for raising errors, throw/1 is for abrupt termination of a computation. > Consider this +1 to the set of people that wants this function in the lists > module :) Wirth (the blessed) said something like (paraphrased) every time we add something to a language we should ask *what can we remove*. If we just add stuff to languages (or libraries) - without removing stuff, we add additional complexity so we violate the principle of being as simple as possible. I am often horrified by libraries that offer dozens of different ways to do essentially the same thing - this makes the documentation almost unreadable (since it is unclear which the kernel methods are) and makes learning very difficult. Libraries should provide a small set of primitive parts which can be glued together to solve a large number of problems. If the set of parts is large then learning the library will be very difficult. If you don't know all the functions in a library then programming using the library will be painfully slow since you will have to google your way through large volumes of documentation. If you really really want fold_until then I suggest you make your own personal library (mylib.erl) where you put fold_until (and every other additional function that you think is missing from the standard libraries) - then one day when you are satisfied that your library has proved useful you can publish it. Exactly what should be in the standard libraries is an extremely difficult problem- I think they should contain small sets of orthogonal functions and err on the side of generality. If two function do more of less the same thing one of them should be removed. /Joe > > /M > > David Mercer wrote: >> >> Why not use throw and catch? ?E.g.: >> >> ?1> SumOr10 = fun(X, Y) when X + Y >= 10 -> throw(10); (X, Y) -> X + Y >> end. >> ?#Fun >> ?2> catch lists:foldl(SumOr10, 0, [1,2,3]). >> ?6 >> ?3> catch lists:foldl(SumOr10, 0, [1,2,3,4]). >> ?10 >> ?4> catch lists:foldl(SumOr10, 0, [1,2,3,4,5]). >> ?10 >> >> >>> >>> -----Original Message----- >>> From: erlang-questions@REDACTED [mailto:erlang-questions@REDACTED] On >>> Behalf Of Juan Jose Comellas >>> Sent: Friday, May 29, 2009 11:16 AM >>> To: Erlang Questions >>> Subject: [erlang-questions] Breaking out of a foldl >>> >>> Several times I've come across the need of a variant of foldl/foldr where >>> I >>> can break out of the iteration before going over allthe elements of a >>> list. >>> Has anybody thought of adding a function like the one below to the lists >>> module? >>> >>> bfoldl(Fun, Acc0, [Head | Tail]) -> >>> ? ?case Fun(Head, Acc0) of >>> ? ? ? ?{ok, Acc} -> >>> ? ? ? ? ? ?bfoldl(Fun, Acc, Tail); >>> ? ? ? ?{break, _Acc} = Result -> >>> ? ? ? ? ? ?Result; >>> ? ? ? ?break -> >>> ? ? ? ? ? ?{break, Acc0} >>> ? ?end; >>> bfoldl(_Fun, Acc0, []) -> >>> ? ?{ok, Acc0}. >>> >>> Where a function can return {ok, Acc} to continue iterating and break / >>> {break, Acc} to interrupt it. >>> >> >> >> ________________________________________________________________ >> erlang-questions mailing list. See http://www.erlang.org/faq.html >> erlang-questions (at) erlang.org >> >> > > > ________________________________________________________________ > erlang-questions mailing list. See http://www.erlang.org/faq.html > erlang-questions (at) erlang.org > > From masse@REDACTED Mon Jun 1 11:10:50 2009 From: masse@REDACTED (mats cronqvist) Date: Mon, 01 Jun 2009 11:10:50 +0200 Subject: Breaking out of a foldl In-Reply-To: <4A215C77.2010606@erlang-consulting.com> (Mazen Harake's message of "Sat\, 30 May 2009 19\:19\:03 +0300") References: <1c3be50f0905290916r11734dc5k820e86be80f737fe@mail.gmail.com> <14F8BA751CA44C5B8A886C6143BE29BE@SSI.CORP> <4A215C77.2010606@erlang-consulting.com> Message-ID: <87iqjgz5d1.fsf@sterlett.hq.kred> Mazen Harake writes: > Because it is a hack? It's most definitely not a "hack". > a "fold_until" would be much smoother. Yes, and a "fold_while", and of course a "fold_if" and trusty old "fold_unless." Or am I being too subtle here? Replacing a general mechanism, i.e. try-catch, with an infinitude of special cases is just lame. > Consider this +1 to the set of people that wants this function in the > lists module :) > > /M > > David Mercer wrote: >> Why not use throw and catch? E.g.: >> >> 1> SumOr10 = fun(X, Y) when X + Y >= 10 -> throw(10); (X, Y) -> X + Y end. >> #Fun >> 2> catch lists:foldl(SumOr10, 0, [1,2,3]). >> 6 >> 3> catch lists:foldl(SumOr10, 0, [1,2,3,4]). >> 10 >> 4> catch lists:foldl(SumOr10, 0, [1,2,3,4,5]). >> 10 >> >> >>> -----Original Message----- >>> From: erlang-questions@REDACTED [mailto:erlang-questions@REDACTED] On >>> Behalf Of Juan Jose Comellas >>> Sent: Friday, May 29, 2009 11:16 AM >>> To: Erlang Questions >>> Subject: [erlang-questions] Breaking out of a foldl >>> >>> Several times I've come across the need of a variant of foldl/foldr where >>> I >>> can break out of the iteration before going over allthe elements of a >>> list. >>> Has anybody thought of adding a function like the one below to the lists >>> module? >>> >>> bfoldl(Fun, Acc0, [Head | Tail]) -> >>> case Fun(Head, Acc0) of >>> {ok, Acc} -> >>> bfoldl(Fun, Acc, Tail); >>> {break, _Acc} = Result -> >>> Result; >>> break -> >>> {break, Acc0} >>> end; >>> bfoldl(_Fun, Acc0, []) -> >>> {ok, Acc0}. >>> >>> Where a function can return {ok, Acc} to continue iterating and break / >>> {break, Acc} to interrupt it. >>> >> >> >> ________________________________________________________________ >> erlang-questions mailing list. See http://www.erlang.org/faq.html >> erlang-questions (at) erlang.org >> >> > > > ________________________________________________________________ > erlang-questions mailing list. See http://www.erlang.org/faq.html > erlang-questions (at) erlang.org From dmitriid@REDACTED Mon Jun 1 11:29:11 2009 From: dmitriid@REDACTED (Dmitrii Dimandt) Date: Mon, 1 Jun 2009 12:29:11 +0300 Subject: Adoption of perl/javascript-style regexp syntax Message-ID: <6DB5F62D-B18D-4302-BCC2-D2FB34BF9B0A@gmail.com> I've just come across re and I like it :) The only issue I have with it is that I have to specify regexps as strings. This leads to ugly-as-hell constucts like these: {ok, Re} = re:compile("(? References: <16244388.165381243688456373.JavaMail.root@zimbra> Message-ID: <4A23A3C4.2080706@hyber.org> Ulf Wiger wrote: > ----- "Christian" wrote: > >> Another source of failure to inspect for you guys is that yaws >> actually reuses processes. Maybe things can leak between requests in >> the process registry, or in the process mailbox. > > This was what I was trying to find out by asking the list. > I have also spent an hour or two walking through the source > in yaws_server.erl, and I must say that it's very difficult > to see how it could happen. > > Also, since yaws reuses processes constantly, and each > acceptor follows the same pattern of 'resetting' the > environment each time, you'd think that it would be a > fairly commonly observed bug. > But there has been such bugs over the years - If they're present in what you run - 1.68 - is hard to say though. /klacke From joelr1@REDACTED Mon Jun 1 12:56:59 2009 From: joelr1@REDACTED (Joel Reymont) Date: Mon, 1 Jun 2009 11:56:59 +0100 Subject: [erlang-questions] Re: how to scale into the cloud using process? example computing simple average In-Reply-To: <14161487.165321243687472220.JavaMail.root@zimbra> References: <14161487.165321243687472220.JavaMail.root@zimbra> Message-ID: <6B2872C0-0704-4F6F-BC61-D62468BBABBE@gmail.com> On May 30, 2009, at 1:44 PM, Ulf Wiger wrote: > Or are you referring to the lack of a 'merge' of > two table copies? Yes. > This is a more difficult thing to > add. Right now, that would have to be done by > extracting records from the non-master, have it > restart and load tables from the master, then > re-inserting the records. Since this cannot be done > within a larger transaction, it might be necessary to > delay requests from the application layer during this > time. I think the only way to solve this would be to keep a separate transaction log. Then you could try to merge the logs from disconnected nodes and re-apply transactions in different order to build a merged database. Then again, who knows what the right order is? Either way, it does not bode well to keeping "account balances" in Mnesia for example, since you could easily overdraw your account if you manage to hit two disconnected nodes. > Which DBMSes have a good solution to this problem? > How do they do it? And what prevents using the same > strategy with mnesia? I think Oracle has a solution. I heard that they use 3 copies of the database to settle on a good one. > (Mnesia's supposed lack of support for handling > partitioned networks has more or less become an > urban legend. An urban legend is a story that's untrue ;-). > Everyone assumes that this is a > major weakness in mnesia, but there is very little > detail about how the competing alternatives > supposedly handle this in a much better way. This is mostly because almost no competing alternative tries to build a multi-master cluster with real-time replication. --- Mac hacker with a performance bent http://www.linkedin.com/in/joelreymont From mazen.harake@REDACTED Mon Jun 1 13:08:34 2009 From: mazen.harake@REDACTED (Mazen Harake) Date: Mon, 01 Jun 2009 14:08:34 +0300 Subject: [erlang-questions] Breaking out of a foldl In-Reply-To: <9b08084c0906010026r23a245bcy23f586ccbe289696@mail.gmail.com> References: <1c3be50f0905290916r11734dc5k820e86be80f737fe@mail.gmail.com> <14F8BA751CA44C5B8A886C6143BE29BE@SSI.CORP> <4A215C77.2010606@erlang-consulting.com> <9b08084c0906010026r23a245bcy23f586ccbe289696@mail.gmail.com> Message-ID: <4A23B6B2.9060407@erlang-consulting.com> Yes smoother. Imagine the code bloat if you want to add a try catch around every other lists:x/y function... Absolutely smoother and nicer code. I use throw all the time for exactly the situation as you describe but on a higher level namely on component level. Now obviously someone is going to suggest to wrap a fold_until loop in a try catch and make a function out of it... well voila (or how ever that is spelt) your back to what I suggested, because wrapping it makes it smooooother. Another very obvious benefit is traceability and that it will be implemnted the same way across so that it will be well tested and safe. I'm sure there are many more... So on the argument of smoother; Yes, it is... In terms of it being a hack; Matter of definition I guess... for the reasons mentioned above I wouldn't recommend using try-catch for solving this problem this leads me to the next question... about the documentation... well there are more highlevel problems with the documentation. It seems you think that "bloating" the documentation is a bad thing for beginners, well I would rather say that the way the documentation is structures is the real problem. E.g. the fact there is no index in the beginning of each module where one can quickly get an overview of the functions. Then there are things like; I have to use google to search it (what??? THAT if something is unsmooth), I have to "know" what I'm looking for E.g. what is the difference between filelib, file, and filename (I'm sure it seems very obvious to us who have used it alot but not to beginners since that is what we are discussing). If you are concerned about beginners (specially beginners coming from OO languages) you should be more worried about ridiculous things like parameterised modules which makes beginners _really_ confused... (Is it an object or not?? specially with the new construct) With that being said I do agree with you that the set of the standard library should be small... but that doesn't mean that just because we want it small we don't include things that _make_sense_ /Mazen Joe Armstrong wrote: > On Sat, May 30, 2009 at 6:19 PM, Mazen Harake > wrote: > >> Because it is a hack? >> >> a "fold_until" would be much smoother. >> > > Uuugh - smoothness????????????? > > Why have two functions when one (the existing foldl) is perfectly adequate? > > The use of throw to abnormally terminate a recursion is not a hack. > That is what > catch-throw was designed to do. exit/1 is for raising errors, throw/1 is for > abrupt termination of a computation. > > >> Consider this +1 to the set of people that wants this function in the lists >> module :) >> > > Wirth (the blessed) said something like (paraphrased) every time we > add something > to a language we should ask *what can we remove*. If we just add stuff > to languages > (or libraries) - without removing stuff, we add additional complexity > so we violate > the principle of being as simple as possible. > > I am often horrified by libraries that offer dozens of different ways > to do essentially the > same thing - this makes the documentation almost unreadable (since it is unclear > which the kernel methods are) and makes learning very difficult. > > Libraries should provide a small set of primitive parts which can be > glued together > to solve a large number of problems. If the set of parts is large then > learning the library will be very difficult. If you don't know all the > functions in a library then > programming using the library will be painfully slow since you will > have to google > your way through large volumes of documentation. > > If you really really want fold_until then I suggest you make your own > personal library > (mylib.erl) where you put fold_until (and every other additional > function that you think > is missing from the standard libraries) - then one day when you are > satisfied that > your library has proved useful you can publish it. > > Exactly what should be in the standard libraries is an extremely > difficult problem- > I think they should contain small sets of orthogonal functions and err > on the side > of generality. If two function do more of less the same thing one of > them should be removed. > > /Joe > > > > >> /M >> >> David Mercer wrote: >> >>> Why not use throw and catch? E.g.: >>> >>> 1> SumOr10 = fun(X, Y) when X + Y >= 10 -> throw(10); (X, Y) -> X + Y >>> end. >>> #Fun >>> 2> catch lists:foldl(SumOr10, 0, [1,2,3]). >>> 6 >>> 3> catch lists:foldl(SumOr10, 0, [1,2,3,4]). >>> 10 >>> 4> catch lists:foldl(SumOr10, 0, [1,2,3,4,5]). >>> 10 >>> >>> >>> >>>> -----Original Message----- >>>> From: erlang-questions@REDACTED [mailto:erlang-questions@REDACTED] On >>>> Behalf Of Juan Jose Comellas >>>> Sent: Friday, May 29, 2009 11:16 AM >>>> To: Erlang Questions >>>> Subject: [erlang-questions] Breaking out of a foldl >>>> >>>> Several times I've come across the need of a variant of foldl/foldr where >>>> I >>>> can break out of the iteration before going over allthe elements of a >>>> list. >>>> Has anybody thought of adding a function like the one below to the lists >>>> module? >>>> >>>> bfoldl(Fun, Acc0, [Head | Tail]) -> >>>> case Fun(Head, Acc0) of >>>> {ok, Acc} -> >>>> bfoldl(Fun, Acc, Tail); >>>> {break, _Acc} = Result -> >>>> Result; >>>> break -> >>>> {break, Acc0} >>>> end; >>>> bfoldl(_Fun, Acc0, []) -> >>>> {ok, Acc0}. >>>> >>>> Where a function can return {ok, Acc} to continue iterating and break / >>>> {break, Acc} to interrupt it. >>>> >>>> >>> ________________________________________________________________ >>> erlang-questions mailing list. See http://www.erlang.org/faq.html >>> erlang-questions (at) erlang.org >>> >>> >>> >> ________________________________________________________________ >> erlang-questions mailing list. See http://www.erlang.org/faq.html >> erlang-questions (at) erlang.org >> >> >> From vincent.dephily@REDACTED Mon Jun 1 13:45:55 2009 From: vincent.dephily@REDACTED (Vincent de Phily) Date: Mon, 1 Jun 2009 13:45:55 +0200 Subject: accessing eeps at erlang.org Message-ID: <200906011345.55887.vincent.dephily@mobile-devices.fr> Have the EEPs moved ? I get 404s for everything under http://www.erlang.org/eeps/ -- Vincent de Phily From ulf.wiger@REDACTED Mon Jun 1 14:17:10 2009 From: ulf.wiger@REDACTED (Ulf Wiger) Date: Mon, 1 Jun 2009 13:17:10 +0100 (BST) Subject: [erlang-questions] Re: how to scale into the cloud using process? example computing simple average In-Reply-To: <5139002.167911243858620554.JavaMail.root@zimbra> Message-ID: <7254392.167931243858630320.JavaMail.root@zimbra> Joel Reymont wrote: > > On May 30, 2009, at 1:44 PM, Ulf Wiger wrote: > > I think the only way to solve this would be to keep a separate > transaction log. Then you could try to merge the logs from > disconnected nodes and re-apply transactions in different order to > build a merged database. > > Then again, who knows what the right order is? This is one of the reasons why it doesn't happen automatically. Merging of records after a split-brain condition is an application-specific problem. Personal Information Managers have had this problem for ages, and usually resort to presenting the user with a list of records that couldn't be deconflicted automatically. Source code merging is another problem with corner cases requiring human intervention. > Either way, it does not bode well to keeping "account balances" in > Mnesia for example, since you could easily overdraw your account if > you manage to hit two disconnected nodes. ...and when building the AXD 301, we were not thrilled by the prospect of having two control processors simultaneously controlling the resources in the ATM switch fabric, so we designed checks to make sure that the processors would be able to determine the source of the problem by asking a third party (the switch). >> Which DBMSes have a good solution to this problem? How do they do >> it? And what prevents using the same strategy with mnesia? > > I think Oracle has a solution. I heard that they use 3 copies of the > database to settle on a good one. What prevents you from doing something similar with mnesia? >> (Mnesia's supposed lack of support for handling partitioned >> networks has more or less become an urban legend. > > An urban legend is a story that's untrue ;-). Exactly. :) >> Everyone assumes that this is a major weakness in mnesia, but there >> is very little detail about how the competing alternatives >> supposedly handle this in a much better way. > > This is mostly because almost no competing alternative tries to build > a multi-master cluster with real-time replication. As far as I know, just about all competing alternatives offer multimaster replication: Oracle, Ingres, MySQL, PostgreSQL, Sybase, SQL Server and DB2 come to mind. At least in one or some of those, if memory serves, the way to recover from partitioned network was to initiate disaster recovery and restart from a stable backup. In one study, this was noted as an example of the type of automatic handling of partitioned networks that mnesia supposedly was unable to provide. Someone with plenty of time on their hands could perhaps inventory the strategies of these products and identify which of these strategies could not be implemented on top of mnesia without major surgery. BR, Ulf W -- Ulf Wiger CTO, Erlang Training & Consulting Ltd. http://www.erlang-consulting.com From vincent.dephily@REDACTED Mon Jun 1 14:37:52 2009 From: vincent.dephily@REDACTED (Vincent de Phily) Date: Mon, 1 Jun 2009 14:37:52 +0200 Subject: [erlang-questions] accessing eeps at erlang.org In-Reply-To: <20090601122446.GA8865@erix.ericsson.se> References: <200906011345.55887.vincent.dephily@mobile-devices.fr> <20090601122446.GA8865@erix.ericsson.se> Message-ID: <200906011437.52277.vincent.dephily@mobile-devices.fr> On Monday 01 June 2009 14:24:46 Raimo Niskanen wrote: > On Mon, Jun 01, 2009 at 01:45:55PM +0200, Vincent de Phily wrote: > > Have the EEPs moved ? I get 404s for everything under > > http://www.erlang.org/eeps/ > > Not really. I am not done setting up the EEP repository after > the server upgrade. The old server is still not dead, > so you can find them at http://old-morgoth.erlang.org/eeps/ Thanks for the link and the maintenance work. -- Vincent de Phily From mike.shaver@REDACTED Mon Jun 1 15:13:19 2009 From: mike.shaver@REDACTED (Mike Shaver) Date: Mon, 1 Jun 2009 09:13:19 -0400 Subject: [erlang-questions] Multi-precision math, random number generator entropy, various other questions In-Reply-To: References: <200905312007.n4VK71Fg002429@pluto.hedeland.org> Message-ID: On Sun, May 31, 2009 at 4:42 PM, Greg Perry wrote: > Unfortunately that depends on the host OS' RNG, Linux and most BSD > variants have quality entropy gathering and RNG functions; Windows > variants not so much. I believe that Windows' CryptGenRandom should suffice, no? (A weakness in the XP implementation was fixed in SP3 last year.) Mike From rvirding@REDACTED Mon Jun 1 15:39:49 2009 From: rvirding@REDACTED (Robert Virding) Date: Mon, 1 Jun 2009 15:39:49 +0200 Subject: [erlang-questions] Adoption of perl/javascript-style regexp syntax In-Reply-To: <6DB5F62D-B18D-4302-BCC2-D2FB34BF9B0A@gmail.com> References: <6DB5F62D-B18D-4302-BCC2-D2FB34BF9B0A@gmail.com> Message-ID: <3dbc6d1c0906010639r603df583i1ef87816306d8f7f@mail.gmail.com> 2009/6/1 Dmitrii Dimandt > I've just come across re and I like it :) > > The only issue I have with it is that I have to specify regexps as strings. > This leads to ugly-as-hell constucts like these: > > {ok, Re} = re:compile("(? > It actually tries to find two backslashes there... Or just one? I don't > know :) What if Erlang could allow this: > > Re = /(? > ? > > Benefits: > - Less error-prone > - Expressions written this way can be parsed and compiled by the compiler > (boost in performance, syntax checked at compile-time) Without getting into discussions if we *want* to do this I can say that I doubt this will boost performance as the PCRE package which the base of re takes its input regular expression as a (C) string. From what I can understand its various parts aren't modular. This is a pity. Robert From ulf.wiger@REDACTED Mon Jun 1 16:17:01 2009 From: ulf.wiger@REDACTED (Ulf Wiger) Date: Mon, 1 Jun 2009 15:17:01 +0100 (BST) Subject: [erlang-questions] Adoption of perl/javascript-style regexp syntax In-Reply-To: <30459.168071243865703384.JavaMail.root@zimbra> Message-ID: <19504077.168111243865821581.JavaMail.root@zimbra> Dmitrii Dimandt wrote: > > I've just come across re and I like it :) > > The only issue I have with it is that I have to specify regexps as > strings. This leads to ugly-as-hell constucts like these: > > {ok, Re} = re:compile("(? > It actually tries to find two backslashes there... Or just one? I > don't know :) What if Erlang could allow this: > > Re = /(? > ? > > Benefits: > - Less error-prone > - Expressions written this way can be parsed and compiled by the > compiler (boost in performance, syntax checked at compile-time) It's not going to boost performance, as this is just a preprocessor issue. But having to escape the backslashes when working with regexps is a pain. Perhaps a better syntax would be to imitate the LaTex \verb command. It allows you to specify the delimiter, and then consumes all chars until it finds that delimiter, e.g. \verb!gdl4$%\^\$?$! Since this exact syntax doesn't work in Erlang, a slight adjustment is in order. The scanner recognizes backticks today, but the parser doesn't. So, if we change the scanner to recognize ` as the Erlang version of \verb, we can write: 1> re:split("foo\nbar",`!\n!). [<<"foo">>,<<"bar">>] where 2> `!\n!. "\\n" Diff follows. It was a quick hack, so it needs improvement. --- /home/uwiger/src/otp/otp_src_R13B/lib/stdlib/src/erl_scan.erl 2009-04-16 05:23:36.000000000 -0400 +++ erl_scan.erl 2009-06-01 09:09:49.000000000 -0400 @@ -559,4 +559,2 @@ tok2(Cs, St, Line, Col, Toks, "^", '^', 1); -scan1([$`|Cs], St, Line, Col, Toks) -> - tok2(Cs, St, Line, Col, Toks, "`", '`', 1); scan1([$~|Cs], St, Line, Col, Toks) -> @@ -565,2 +563,4 @@ tok2(Cs, St, Line, Col, Toks, "&", '&', 1); +scan1([$`|Cs], St, Line, Col, Toks) -> + scan_verb(Cs, St, Line, Col, Toks, []); %% End of optimization. @@ -580,2 +580,27 @@ +scan_verb([], _St, Line, Col, Toks, Acc) -> + {more, {[],Col,Toks,Line,Acc,fun scan_verb/6}}; +scan_verb([Delim|Cs0], St, Line, Col, Toks, Acc) when Delim =/= $\n, + Delim =/= $\\ -> + {Str, Cs, Line1, Col1} = scan_verb_chars( + Cs0, St, Line, Col, Toks, {Acc,Delim}), + tok3(Cs, St, Line1, Col1, Toks, string, Str, Str, 0). + +scan_verb_chars([], _St, Line, Col, Toks, {Acc, Delim}) -> + {more, {[], Col, Toks, Line, {Acc,Delim}, fun scan_verb_chars/6}}; +scan_verb_chars([Delim|Cs], _St, Line, Col, Toks, {Acc, Delim}) -> + {lists:reverse(Acc), Cs, Line, Col}; +scan_verb_chars([C|Cs], St, Line, Col, Toks, {Acc, Delim}) when C =/= Delim-> + {Line1,Col1} = case C of + $\n -> + {Line+1, Col}; + _ -> + {Line, inc_col(Col,1)} + end, + scan_verb_chars(Cs, St, Line1, Col1, Toks, {[C|Acc], Delim}). + +inc_col(no_col,_) -> no_col; +inc_col(C, N) when is_integer(C) -> C+N. + + scan_atom(Cs0, St, Line, Col, Toks, Ncs0) -> -- Ulf Wiger CTO, Erlang Training & Consulting Ltd. http://www.erlang-consulting.com From rapsey@REDACTED Mon Jun 1 17:53:47 2009 From: rapsey@REDACTED (Rapsey) Date: Mon, 1 Jun 2009 17:53:47 +0200 Subject: sha-2 Message-ID: <97619b170906010853w29a041duf52ef8f51efe80d1@mail.gmail.com> Are there any plans to add sha-2 (SHA-224, SHA-256, SHA-384, SHA-512) support to the crypto module? thank you, Sergej From Greg.Perry@REDACTED Mon Jun 1 19:48:07 2009 From: Greg.Perry@REDACTED (Greg Perry) Date: Mon, 1 Jun 2009 10:48:07 -0700 Subject: Erlang case statement questions Message-ID: Ok I've put together a simple module declaration but I am getting an error on this case statement. What am I doing wrong with this? N is an integer that gets passed to the module, based upon the return of N rem 9, PQ then gets assigned the list of items on the right: ---------- analyze(N) -> case (N rem 9) of 1 -> PQ = [{1,1}, {2,5}, {4,7}, {8,8}]; 2 -> PQ = [{1,2}, {4,5}, {7,8}]; 3 -> PQ = [{1,3}, {2,6}, {3,4}, {3,7}, {5,6}, {6,8}]; 4 -> PQ = [{1,4}, {2,2}, {5,8}, {7,7}]; 5 -> PQ = [{1,5}, {2,7}, {4,8}]; 6 -> PQ = [{1,6}, {2,3}, {3,5}, {3,8}, {4,6}, {6,7}]; 7 -> PQ = [{1,7}, {2,8}, {4,4}, {5,5}]; 8 -> PQ = [{1,8}, {2,4}, {5,7}]; 9 -> PQ = [{1,9}, {2,9}, {3,3}, {3,6}, {3,9}, {4,9}, {5,9}, {6,6}, {6,9}, {7,9}, {8,9}, {9,9}]; end. ---------- I used the example in Joe's Programming Erlang book for the case statement, but got something wrong obviously. Thanks in advance, Greg From ngreco@REDACTED Mon Jun 1 19:51:46 2009 From: ngreco@REDACTED (Nahuel Greco) Date: Mon, 1 Jun 2009 14:51:46 -0300 Subject: [erlang-questions] Erlang case statement questions In-Reply-To: References: Message-ID: <47d93090906011051n46628186hd50e30f37ee15160@mail.gmail.com> End the last clause without the semicolon. Saludos, Nahuel Greco. On Mon, Jun 1, 2009 at 2:48 PM, Greg Perry wrote: > Ok I've put together a simple module declaration but I am getting an > error on this case statement. ?What am I doing wrong with this? ?N is an > integer that gets passed to the module, based upon the return of N rem > 9, PQ then gets assigned the list of items on the right: > > ---------- > > analyze(N) -> > ? case (N rem 9) of > ? ? ?1 -> PQ = [{1,1}, {2,5}, {4,7}, {8,8}]; > ? ? ?2 -> PQ = [{1,2}, {4,5}, {7,8}]; > ? ? ?3 -> PQ = [{1,3}, {2,6}, {3,4}, {3,7}, {5,6}, {6,8}]; > ? ? ?4 -> PQ = [{1,4}, {2,2}, {5,8}, {7,7}]; > ? ? ?5 -> PQ = [{1,5}, {2,7}, {4,8}]; > ? ? ?6 -> PQ = [{1,6}, {2,3}, {3,5}, {3,8}, {4,6}, {6,7}]; > ? ? ?7 -> PQ = [{1,7}, {2,8}, {4,4}, {5,5}]; > ? ? ?8 -> PQ = [{1,8}, {2,4}, {5,7}]; > ? ? ?9 -> PQ = [{1,9}, {2,9}, {3,3}, {3,6}, {3,9}, {4,9}, {5,9}, {6,6}, > {6,9}, {7,9}, {8,9}, {9,9}]; > ? end. > > ---------- > > I used the example in Joe's Programming Erlang book for the case > statement, but got something wrong obviously. > > Thanks in advance, > > Greg > > > > > ________________________________________________________________ > erlang-questions mailing list. See http://www.erlang.org/faq.html > erlang-questions (at) erlang.org > From torben.lehoff@REDACTED Mon Jun 1 20:18:38 2009 From: torben.lehoff@REDACTED (Torben Hoffmann) Date: Mon, 1 Jun 2009 20:18:38 +0200 Subject: [erlang-questions] sha-2 In-Reply-To: <97619b170906010853w29a041duf52ef8f51efe80d1@mail.gmail.com> References: <97619b170906010853w29a041duf52ef8f51efe80d1@mail.gmail.com> Message-ID: http://steve.vinoski.net/blog/2009/01/03/more-sha-in-erlang/ Cheers, Torben On Mon, Jun 1, 2009 at 5:53 PM, Rapsey wrote: > Are there any plans to add sha-2 (SHA-224, SHA-256, SHA-384, SHA-512) > support to the crypto module? > > > thank you, > Sergej > From rapsey@REDACTED Mon Jun 1 20:43:53 2009 From: rapsey@REDACTED (Rapsey) Date: Mon, 1 Jun 2009 20:43:53 +0200 Subject: [erlang-questions] sha-2 In-Reply-To: References: <97619b170906010853w29a041duf52ef8f51efe80d1@mail.gmail.com> Message-ID: <97619b170906011143s1606f738iead68e26fdc072b0@mail.gmail.com> Yeah I know about that implementation. But it would be nice to have it in crypto and backed by OpenSSL which would be much faster. Sergej On Mon, Jun 1, 2009 at 8:18 PM, Torben Hoffmann < torben.lehoff@REDACTED> wrote: > http://steve.vinoski.net/blog/2009/01/03/more-sha-in-erlang/ > > Cheers, > Torben > > > On Mon, Jun 1, 2009 at 5:53 PM, Rapsey wrote: > >> Are there any plans to add sha-2 (SHA-224, SHA-256, SHA-384, SHA-512) >> support to the crypto module? >> >> >> thank you, >> Sergej >> > > From attila.r.nohl@REDACTED Mon Jun 1 20:44:01 2009 From: attila.r.nohl@REDACTED (Attila Rajmund Nohl) Date: Mon, 1 Jun 2009 20:44:01 +0200 Subject: [erlang-questions] Breaking out of a foldl In-Reply-To: <401d3ba30906010427l7fe8df0at890dd16752131ae1@mail.gmail.com> References: <1c3be50f0905290916r11734dc5k820e86be80f737fe@mail.gmail.com> <14F8BA751CA44C5B8A886C6143BE29BE@SSI.CORP> <4A215C77.2010606@erlang-consulting.com> <9b08084c0906010026r23a245bcy23f586ccbe289696@mail.gmail.com> <401d3ba30906010427l7fe8df0at890dd16752131ae1@mail.gmail.com> Message-ID: <401d3ba30906011144p45133964pae69268778b34138@mail.gmail.com> 2009/6/1, Joe Armstrong : > On Sat, May 30, 2009 at 6:19 PM, Mazen Harake > wrote: >> Because it is a hack? >> >> a "fold_until" would be much smoother. > > Uuugh - smoothness????????????? > > Why have two functions when one (the existing foldl) is perfectly adequate? > > The use of throw to abnormally terminate a recursion is not a hack. > That is what > catch-throw was designed to do. exit/1 is for raising errors, throw/1 is for > abrupt termination of a computation. Yeah, but it's syntax is somewhat misleading. People with Java/C++/Eiffel/etc. background would expect that exceptions should be used in exceptional situation, not instead of a return statement (which Erlang lacks). [...] > Wirth (the blessed) said something like (paraphrased) every time we > add something > to a language we should ask *what can we remove*. If we just add stuff > to languages > (or libraries) - without removing stuff, we add additional complexity > so we violate > the principle of being as simple as possible. > > I am often horrified by libraries that offer dozens of different ways > to do essentially the > same thing - this makes the documentation almost unreadable (since it is > unclear > which the kernel methods are) and makes learning very difficult. > > Libraries should provide a small set of primitive parts which can be > glued together > to solve a large number of problems. If the set of parts is large then > learning the library will be very difficult. If you don't know all the > functions in a library then > programming using the library will be painfully slow since you will > have to google > your way through large volumes of documentation. > > If you really really want fold_until then I suggest you make your own > personal library > (mylib.erl) where you put fold_until (and every other additional > function that you think > is missing from the standard libraries) - then one day when you are > satisfied that > your library has proved useful you can publish it. > > Exactly what should be in the standard libraries is an extremely > difficult problem- > I think they should contain small sets of orthogonal functions and err > on the side > of generality. If two function do more of less the same thing one of > them should be removed. I disagree. Every Erlang project I've seen had it's own tracing module built on top of dbg. They all had very similar functions that did nearly the same thing. This obviously means that the dbg module needs a function that simply turns on tracing on a function of a module. Yes, it could be done with dbg:tpl, but why shall I type every time [{'_',[],[{return_trace}]}] into the shell? Also the equivalent of lists:keyfind was probably implemented countless times in most Erlang projects. I do think it's better to have often needed code in the standard library. First of all, it's standard, so every programmer should be familiar with it. On the other hand the "helper" functions in the various mylib libraries are probably not well known to anyone except the author. The above mentioned tracing modules had functions doing essentially the same, but each with a slightly different syntax which is quite annoying. Using third party libraries (e.g. someone's released mylib) has other drawbacks. It might not be useable at all due to licensing. It's an other dependency that has to be followed (e.g. when a bugfix release comes out). It might not be maintained anymore. It doesn't have the same user base as the standard library, so it might have more bugs. >From the management point of view it's better to work with the standard library and in-house code, without 3rd party libraries. I think that the standard library should first and foremost make programming easier. For example, the JTable class in Java has 7 constructors. A couple of them probably could be removed to get a more minimal code - but the removed code will popup in the applications many more times and probably with many more bugs. From dmercer@REDACTED Mon Jun 1 21:05:26 2009 From: dmercer@REDACTED (David Mercer) Date: Mon, 1 Jun 2009 14:05:26 -0500 Subject: [erlang-questions] Breaking out of a foldl In-Reply-To: <401d3ba30906011144p45133964pae69268778b34138@mail.gmail.com> References: <1c3be50f0905290916r11734dc5k820e86be80f737fe@mail.gmail.com> <14F8BA751CA44C5B8A886C6143BE29BE@SSI.CORP> <4A215C77.2010606@erlang-consulting.com> <9b08084c0906010026r23a245bcy23f586ccbe289696@mail.gmail.com> <401d3ba30906010427l7fe8df0at890dd16752131ae1@mail.gmail.com> <401d3ba30906011144p45133964pae69268778b34138@mail.gmail.com> Message-ID: > Yeah, but it's syntax is somewhat misleading. People with > Java/C++/Eiffel/etc. background would expect that exceptions should be > used in exceptional situation, not instead of a return statement > (which Erlang lacks). But throw/1 is not used to throw exceptions: it is used to throw (quoting from the documentation) "A non-local return from a function." That seems to fit the bill in this case. That other languages make throwing expensive enough to recommend that it only be used in exceptional circumstances is a restriction on their implementations, not Erlang's. > -----Original Message----- > From: erlang-questions@REDACTED [mailto:erlang-questions@REDACTED] On > Behalf Of Attila Rajmund Nohl > Sent: Monday, June 01, 2009 1:44 PM > To: erlang-questions@REDACTED > Subject: [erlang-questions] Breaking out of a foldl > > 2009/6/1, Joe Armstrong : > > On Sat, May 30, 2009 at 6:19 PM, Mazen Harake > > wrote: > >> Because it is a hack? > >> > >> a "fold_until" would be much smoother. > > > > Uuugh - smoothness????????????? > > > > Why have two functions when one (the existing foldl) is perfectly > adequate? > > > > The use of throw to abnormally terminate a recursion is not a hack. > > That is what > > catch-throw was designed to do. exit/1 is for raising errors, throw/1 is > for > > abrupt termination of a computation. > > Yeah, but it's syntax is somewhat misleading. People with > Java/C++/Eiffel/etc. background would expect that exceptions should be > used in exceptional situation, not instead of a return statement > (which Erlang lacks). > > [...] > > Wirth (the blessed) said something like (paraphrased) every time we > > add something > > to a language we should ask *what can we remove*. If we just add stuff > > to languages > > (or libraries) - without removing stuff, we add additional complexity > > so we violate > > the principle of being as simple as possible. > > > > I am often horrified by libraries that offer dozens of different ways > > to do essentially the > > same thing - this makes the documentation almost unreadable (since it is > > unclear > > which the kernel methods are) and makes learning very difficult. > > > > Libraries should provide a small set of primitive parts which can be > > glued together > > to solve a large number of problems. If the set of parts is large then > > learning the library will be very difficult. If you don't know all the > > functions in a library then > > programming using the library will be painfully slow since you will > > have to google > > your way through large volumes of documentation. > > > > If you really really want fold_until then I suggest you make your own > > personal library > > (mylib.erl) where you put fold_until (and every other additional > > function that you think > > is missing from the standard libraries) - then one day when you are > > satisfied that > > your library has proved useful you can publish it. > > > > Exactly what should be in the standard libraries is an extremely > > difficult problem- > > I think they should contain small sets of orthogonal functions and err > > on the side > > of generality. If two function do more of less the same thing one of > > them should be removed. > > I disagree. Every Erlang project I've seen had it's own tracing module > built on top of dbg. They all had very similar functions that did > nearly the same thing. This obviously means that the dbg module needs > a function that simply turns on tracing on a function of a module. > Yes, it could be done with dbg:tpl, but why shall I type every time > [{'_',[],[{return_trace}]}] into the shell? Also the equivalent of > lists:keyfind was probably implemented countless times in most Erlang > projects. > > I do think it's better to have often needed code in the standard > library. First of all, it's standard, so every programmer should be > familiar with it. On the other hand the "helper" functions in the > various mylib libraries are probably not well known to anyone except > the author. The above mentioned tracing modules had functions doing > essentially the same, but each with a slightly different syntax which > is quite annoying. > > Using third party libraries (e.g. someone's released mylib) has other > drawbacks. It might not be useable at all due to licensing. It's an > other dependency that has to be followed (e.g. when a bugfix release > comes out). It might not be maintained anymore. It doesn't have the > same user base as the standard library, so it might have more bugs. > From the management point of view it's better to work with the > standard library and in-house code, without 3rd party libraries. > > I think that the standard library should first and foremost make > programming easier. For example, the JTable class in Java has 7 > constructors. A couple of them probably could be removed to get a more > minimal code - but the removed code will popup in the applications > many more times and probably with many more bugs. > > ________________________________________________________________ > erlang-questions mailing list. See http://www.erlang.org/faq.html > erlang-questions (at) erlang.org From torben.lehoff@REDACTED Mon Jun 1 21:06:47 2009 From: torben.lehoff@REDACTED (Torben Hoffmann) Date: Mon, 1 Jun 2009 21:06:47 +0200 Subject: [erlang-questions] sha-2 In-Reply-To: <97619b170906011143s1606f738iead68e26fdc072b0@mail.gmail.com> References: <97619b170906010853w29a041duf52ef8f51efe80d1@mail.gmail.com> <97619b170906011143s1606f738iead68e26fdc072b0@mail.gmail.com> Message-ID: I agree on the speed, but crypto's dependency on OpenSSL makes shipping a product a bit harder since you have to bundle it with OpenSSL as well. And this makest harder to make a distribution for multiple platforms. But if you need more than the SHA functions from crypto or distribution is not an issue then crypto is the choice... unless you sit down and implent what you are missing in Erlang!! ;-) Cheers, Torben On Mon, Jun 1, 2009 at 8:43 PM, Rapsey wrote: > Yeah I know about that implementation. But it would be nice to have it in > crypto and backed by OpenSSL which would be much faster. > > > Sergej > > On Mon, Jun 1, 2009 at 8:18 PM, Torben Hoffmann < > torben.lehoff@REDACTED> wrote: > > > http://steve.vinoski.net/blog/2009/01/03/more-sha-in-erlang/ > > > > Cheers, > > Torben > > > > > > On Mon, Jun 1, 2009 at 5:53 PM, Rapsey wrote: > > > >> Are there any plans to add sha-2 (SHA-224, SHA-256, SHA-384, SHA-512) > >> support to the crypto module? > >> > >> > >> thank you, > >> Sergej > >> > > > > > From prikrutil@REDACTED Mon Jun 1 21:50:24 2009 From: prikrutil@REDACTED (Sergey Samokhin) Date: Mon, 1 Jun 2009 12:50:24 -0700 Subject: Why doesn't backup/restore work for me? Message-ID: Hello. After mnesia:restore/2 has been applied, I don't see the records restored from backup made by mnesia:backup/1 (which is supposed to create complete backup of all the table if I don't make a mistake). I must have missed something significant, but I don't see what exactly. Here is example: %%%%%%%%%%%% test() -> mnesia:start(), mnesia:create_table(foo, []), [mnesia:dirty_write({foo, N, -N}) || N <- lists:seq(1, 100)], io:format("# ~p records inserted~n", [mnesia:table_info(foo, size)]), mnesia:backup(backup_file), mnesia:clear_table(foo), mnesia:restore(backup_file, []), io:format("# ~p records restored~n", [mnesia:table_info(foo, size)]). %%%%%%%%%%%% Results: 1> test:test(). # 100 records inserted # 0 records restored Thanks. -- Sergey Samokhin From raould@REDACTED Mon Jun 1 22:04:44 2009 From: raould@REDACTED (Raoul Duke) Date: Mon, 1 Jun 2009 13:04:44 -0700 Subject: [erlang-questions] Erlang case statement questions In-Reply-To: <47d93090906011051n46628186hd50e30f37ee15160@mail.gmail.com> References: <47d93090906011051n46628186hd50e30f37ee15160@mail.gmail.com> Message-ID: <91a2ba3e0906011304n3e781f6dxad355c0019ca8e6b@mail.gmail.com> > End the last clause without the semicolon. gotta say i like the thought of LfE syntax better all the time ;-) ;-) From tony@REDACTED Mon Jun 1 21:05:19 2009 From: tony@REDACTED (Tony Rogvall) Date: Mon, 1 Jun 2009 21:05:19 +0200 Subject: [erlang-questions] Erlang case statement questions In-Reply-To: <47d93090906011051n46628186hd50e30f37ee15160@mail.gmail.com> References: <47d93090906011051n46628186hd50e30f37ee15160@mail.gmail.com> Message-ID: <532D1C75-4576-40B6-B6B0-1C9248E4A3C2@rogvall.se> Also. 9 rem 9 = 0! So I guess your cases should be from 0 to 8 or something similar. /Tony On 1 jun 2009, at 19.51, Nahuel Greco wrote: > End the last clause without the semicolon. > > Saludos, > Nahuel Greco. > > > > On Mon, Jun 1, 2009 at 2:48 PM, Greg Perry > wrote: >> Ok I've put together a simple module declaration but I am getting an >> error on this case statement. What am I doing wrong with this? N >> is an >> integer that gets passed to the module, based upon the return of N >> rem >> 9, PQ then gets assigned the list of items on the right: >> >> ---------- >> >> analyze(N) -> >> case (N rem 9) of >> 1 -> PQ = [{1,1}, {2,5}, {4,7}, {8,8}]; >> 2 -> PQ = [{1,2}, {4,5}, {7,8}]; >> 3 -> PQ = [{1,3}, {2,6}, {3,4}, {3,7}, {5,6}, {6,8}]; >> 4 -> PQ = [{1,4}, {2,2}, {5,8}, {7,7}]; >> 5 -> PQ = [{1,5}, {2,7}, {4,8}]; >> 6 -> PQ = [{1,6}, {2,3}, {3,5}, {3,8}, {4,6}, {6,7}]; >> 7 -> PQ = [{1,7}, {2,8}, {4,4}, {5,5}]; >> 8 -> PQ = [{1,8}, {2,4}, {5,7}]; >> 9 -> PQ = [{1,9}, {2,9}, {3,3}, {3,6}, {3,9}, {4,9}, {5,9}, >> {6,6}, >> {6,9}, {7,9}, {8,9}, {9,9}]; >> end. >> >> ---------- >> >> I used the example in Joe's Programming Erlang book for the case >> statement, but got something wrong obviously. >> >> Thanks in advance, >> >> Greg >> >> >> >> >> ________________________________________________________________ >> erlang-questions mailing list. See http://www.erlang.org/faq.html >> erlang-questions (at) erlang.org >> > > ________________________________________________________________ > erlang-questions mailing list. See http://www.erlang.org/faq.html > erlang-questions (at) erlang.org > From ryan@REDACTED Mon Jun 1 22:20:04 2009 From: ryan@REDACTED (Ryan Davis) Date: Mon, 01 Jun 2009 16:20:04 -0400 Subject: problem using erlsrv on windows server 2008 Message-ID: <4A2437F4.2060305@acceleration.net> I'm trying to run rabbitmq as a service on Windows Server 2008, and running into some weird problems. I'm new to erlang, so please forgive me when I use the wrong terms. Rabbitmq is running as a windows service using erlsrv.exe, under the system account. When I login as my user and trying to query it for status, I cannot connect to the rabbit erlang node. Some googling (and a thread on the rabbitmq-discuss list ) indicated this was a cookie issue, that my user's erlang cookie wasn't matching the system account's cookie, so therefore I didn't have any permission to connect to the system's nodes. Unfortunately, making the .erlang.cookie files in "C:\Windows" and "C:\Users\Ryan" identical did not solve my problem completely. I now see some odd behavior: If I login and try to get rabbit status, I cannot connect to the running erlang. If I restart the rabbit service, then I can connect just fine. If I log out and then log back in, I can't connect. I've verified that my .erlang.cookie is not changing between logins. My best guesses are: 1. Erlsrv is changing it's cookie after I logout (doesn't make sense) 2. Windows Server 2008 is denying the connection due to some firewall / permissions rule I can't find (more likely, but why can I connect at all if there's some rule blocking it?) I have added a firewall rules to open: * anything for erl5.7.1\erts-5.7.1\bin\erl.exe * anything for erl5.7.1\bin\erl.exe I was unable to find anything on google about this issue. Has anyone else had similar problems? Should I instead pursue adding a server and getting a Linux-based solution (read: is Windows a second-class citizen with Erlang)? Thanks, -- Ryan Davis Acceleration.net Director of Programming Services 2831 NW 41st street, suite B Gainesville, FL 32606 Office: 352-335-6500 x 124 Fax: 352-335-6506 From erlangy@REDACTED Mon Jun 1 22:31:58 2009 From: erlangy@REDACTED (Michael McDaniel) Date: Mon, 1 Jun 2009 13:31:58 -0700 Subject: [erlang-questions] problem using erlsrv on windows server 2008 In-Reply-To: <4A2437F4.2060305@acceleration.net> References: <4A2437F4.2060305@acceleration.net> Message-ID: <20090601203158.GG11919@delora.autosys.us> Though I am not an MS windows user, I noticed you have not mentioned this cookie C:\Documents and Settings\User\.erlang.cookie as described here ... http://www.rabbitmq.com/install.html ~Michael On Mon, Jun 01, 2009 at 04:20:04PM -0400, Ryan Davis wrote: > I'm trying to run rabbitmq as a service on > Windows Server 2008, and running into some weird problems. I'm new to > erlang, so please forgive me when I use the wrong terms. > > Rabbitmq is running as a windows service using erlsrv.exe, under the > system account. When I login as my user and trying to query it for > status, I cannot connect to the rabbit erlang node. Some googling (and > a thread on the rabbitmq-discuss list > ) > indicated this was a cookie issue, that my user's erlang cookie wasn't > matching the system account's cookie, so therefore I didn't have any > permission to connect to the system's nodes. Unfortunately, making the > .erlang.cookie files in "C:\Windows" and "C:\Users\Ryan" identical did > not solve my problem completely. I now see some odd behavior: > > If I login and try to get rabbit status, I cannot connect to the running > erlang. If I restart the rabbit service, then I can connect just fine. > If I log out and then log back in, I can't connect. I've verified that > my .erlang.cookie is not changing between logins. > > My best guesses are: > > 1. Erlsrv is changing it's cookie after I logout (doesn't make sense) > 2. Windows Server 2008 is denying the connection due to some firewall > / permissions rule I can't find (more likely, but why can I > connect at all if there's some rule blocking it?) > > I have added a firewall rules to open: > > * anything for erl5.7.1\erts-5.7.1\bin\erl.exe > * anything for erl5.7.1\bin\erl.exe > > I was unable to find anything on google about this issue. Has anyone > else had similar problems? Should I instead pursue adding a server and > getting a Linux-based solution (read: is Windows a second-class citizen > with Erlang)? > > Thanks, > > -- > Ryan Davis > Acceleration.net > Director of Programming Services > 2831 NW 41st street, suite B > Gainesville, FL 32606 > > Office: 352-335-6500 x 124 > Fax: 352-335-6506 > -- Michael McDaniel Portland, Oregon, USA http://autosys.us From ryan@REDACTED Mon Jun 1 23:11:03 2009 From: ryan@REDACTED (Ryan Davis) Date: Mon, 01 Jun 2009 17:11:03 -0400 Subject: [Spam] Re: [erlang-questions] problem using erlsrv on windows server 2008 In-Reply-To: <20090601203158.GG11919@delora.autosys.us> References: <4A2437F4.2060305@acceleration.net> <20090601203158.GG11919@delora.autosys.us> Message-ID: <4A2443E7.70401@acceleration.net> Michael McDaniel wrote: > Though I am not an MS windows user, I noticed you have not > mentioned this cookie > > C:\Documents and Settings\User\.erlang.cookie > > as described here ... > > http://www.rabbitmq.com/install.html > > > ~Michael > I have reviewed that page extensively. "C:\Users" is the new "/home" equivalent in Windows 2008 (not sure why they keep changing it). I have tried copying the .erlang.cookie into several different directories in my user folder (including the %APPDATA% directory). I've also launched an erlang shell (using erl5.7.1/bin/erl.exe -sname "test" -cookie coo) and erlang:get_cookie/0 matches the contents of the system .erlang.cookie file. I have changed the provided rabbitmqctl.bat command to include the "-cookie coo" flag, and still no dice. Thanks, Ryan Davis Acceleration.net Director of Programming Services 2831 NW 41st street, suite B Gainesville, FL 32606 Office: 352-335-6500 x 124 Fax: 352-335-6506 From keith.irwin@REDACTED Tue Jun 2 00:11:03 2009 From: keith.irwin@REDACTED (Keith Irwin) Date: Mon, 1 Jun 2009 15:11:03 -0700 Subject: [erlang-questions] Erlang case statement questions In-Reply-To: <532D1C75-4576-40B6-B6B0-1C9248E4A3C2@rogvall.se> References: <47d93090906011051n46628186hd50e30f37ee15160@mail.gmail.com> <532D1C75-4576-40B6-B6B0-1C9248E4A3C2@rogvall.se> Message-ID: <8aff81590906011511w5379ebfau2c35ba781028d774@mail.gmail.com> Also, PQ is thrown away after the end if the statement. Maybe: analyze(N) -> PQ = case (N rem 9) of 1 -> [{1,1}, {2,5}, {4,7}, {8,8}] % etc, etc end, do_something_with(PQ). On Mon, Jun 1, 2009 at 12:05 PM, Tony Rogvall wrote: > Also. 9 rem 9 = 0! > So I guess your cases should be from 0 to 8 or something similar. > > /Tony > > > On 1 jun 2009, at 19.51, Nahuel Greco wrote: > > End the last clause without the semicolon. >> >> Saludos, >> Nahuel Greco. >> >> >> >> On Mon, Jun 1, 2009 at 2:48 PM, Greg Perry >> wrote: >> >>> Ok I've put together a simple module declaration but I am getting an >>> error on this case statement. What am I doing wrong with this? N is an >>> integer that gets passed to the module, based upon the return of N rem >>> 9, PQ then gets assigned the list of items on the right: >>> >>> ---------- >>> >>> analyze(N) -> >>> case (N rem 9) of >>> 1 -> PQ = [{1,1}, {2,5}, {4,7}, {8,8}]; >>> 2 -> PQ = [{1,2}, {4,5}, {7,8}]; >>> 3 -> PQ = [{1,3}, {2,6}, {3,4}, {3,7}, {5,6}, {6,8}]; >>> 4 -> PQ = [{1,4}, {2,2}, {5,8}, {7,7}]; >>> 5 -> PQ = [{1,5}, {2,7}, {4,8}]; >>> 6 -> PQ = [{1,6}, {2,3}, {3,5}, {3,8}, {4,6}, {6,7}]; >>> 7 -> PQ = [{1,7}, {2,8}, {4,4}, {5,5}]; >>> 8 -> PQ = [{1,8}, {2,4}, {5,7}]; >>> 9 -> PQ = [{1,9}, {2,9}, {3,3}, {3,6}, {3,9}, {4,9}, {5,9}, {6,6}, >>> {6,9}, {7,9}, {8,9}, {9,9}]; >>> end. >>> >>> ---------- >>> >>> I used the example in Joe's Programming Erlang book for the case >>> statement, but got something wrong obviously. >>> >>> Thanks in advance, >>> >>> Greg >>> >>> >>> >>> >>> ________________________________________________________________ >>> erlang-questions mailing list. See http://www.erlang.org/faq.html >>> erlang-questions (at) erlang.org >>> >>> >> ________________________________________________________________ >> erlang-questions mailing list. See http://www.erlang.org/faq.html >> erlang-questions (at) erlang.org >> >> > > ________________________________________________________________ > erlang-questions mailing list. See http://www.erlang.org/faq.html > erlang-questions (at) erlang.org > > From keith.irwin@REDACTED Tue Jun 2 00:12:23 2009 From: keith.irwin@REDACTED (Keith Irwin) Date: Mon, 1 Jun 2009 15:12:23 -0700 Subject: [erlang-questions] Erlang case statement questions In-Reply-To: <8aff81590906011511w5379ebfau2c35ba781028d774@mail.gmail.com> References: <47d93090906011051n46628186hd50e30f37ee15160@mail.gmail.com> <532D1C75-4576-40B6-B6B0-1C9248E4A3C2@rogvall.se> <8aff81590906011511w5379ebfau2c35ba781028d774@mail.gmail.com> Message-ID: <8aff81590906011512s3c1a125apa9856d2a4dcd42dc@mail.gmail.com> Actually, you don't need PQ at all. You can just return the value of the case expression itself. K On Mon, Jun 1, 2009 at 3:11 PM, Keith Irwin wrote: > Also, PQ is thrown away after the end if the statement. > Maybe: > > analyze(N) -> > PQ = case (N rem 9) of > 1 -> [{1,1}, {2,5}, {4,7}, {8,8}] > % etc, etc > end, > do_something_with(PQ). > > > On Mon, Jun 1, 2009 at 12:05 PM, Tony Rogvall wrote: > >> Also. 9 rem 9 = 0! >> So I guess your cases should be from 0 to 8 or something similar. >> >> /Tony >> >> >> On 1 jun 2009, at 19.51, Nahuel Greco wrote: >> >> End the last clause without the semicolon. >>> >>> Saludos, >>> Nahuel Greco. >>> >>> >>> >>> On Mon, Jun 1, 2009 at 2:48 PM, Greg Perry >>> wrote: >>> >>>> Ok I've put together a simple module declaration but I am getting an >>>> error on this case statement. What am I doing wrong with this? N is an >>>> integer that gets passed to the module, based upon the return of N rem >>>> 9, PQ then gets assigned the list of items on the right: >>>> >>>> ---------- >>>> >>>> analyze(N) -> >>>> case (N rem 9) of >>>> 1 -> PQ = [{1,1}, {2,5}, {4,7}, {8,8}]; >>>> 2 -> PQ = [{1,2}, {4,5}, {7,8}]; >>>> 3 -> PQ = [{1,3}, {2,6}, {3,4}, {3,7}, {5,6}, {6,8}]; >>>> 4 -> PQ = [{1,4}, {2,2}, {5,8}, {7,7}]; >>>> 5 -> PQ = [{1,5}, {2,7}, {4,8}]; >>>> 6 -> PQ = [{1,6}, {2,3}, {3,5}, {3,8}, {4,6}, {6,7}]; >>>> 7 -> PQ = [{1,7}, {2,8}, {4,4}, {5,5}]; >>>> 8 -> PQ = [{1,8}, {2,4}, {5,7}]; >>>> 9 -> PQ = [{1,9}, {2,9}, {3,3}, {3,6}, {3,9}, {4,9}, {5,9}, {6,6}, >>>> {6,9}, {7,9}, {8,9}, {9,9}]; >>>> end. >>>> >>>> ---------- >>>> >>>> I used the example in Joe's Programming Erlang book for the case >>>> statement, but got something wrong obviously. >>>> >>>> Thanks in advance, >>>> >>>> Greg >>>> >>>> >>>> >>>> >>>> ________________________________________________________________ >>>> erlang-questions mailing list. See http://www.erlang.org/faq.html >>>> erlang-questions (at) erlang.org >>>> >>>> >>> ________________________________________________________________ >>> erlang-questions mailing list. See http://www.erlang.org/faq.html >>> erlang-questions (at) erlang.org >>> >>> >> >> ________________________________________________________________ >> erlang-questions mailing list. See http://www.erlang.org/faq.html >> erlang-questions (at) erlang.org >> >> > From Greg.Perry@REDACTED Tue Jun 2 01:32:40 2009 From: Greg.Perry@REDACTED (Greg Perry) Date: Mon, 1 Jun 2009 16:32:40 -0700 Subject: Converting a string to integer Message-ID: Ok I have another weird problem. I have a file that contains a single line that is a large number. The file is read using read_file with the second element of the tuple extracted: myfile.txt: 123456 element(2,file:read_file("myfile.txt")). <<"123456"...>> Why don't this work? io_lib:fread("~d", element(2,file:read_file("myfile.txt"))). {error,{fread,integer}} What would the easiest way be to extract a single line from a file and convert it to an integer (for example the second element from a tuple that read_file is assigned to)? Thanks in advance Greg From bflatmaj7th@REDACTED Tue Jun 2 01:40:59 2009 From: bflatmaj7th@REDACTED (Richard Andrews) Date: Tue, 2 Jun 2009 09:40:59 +1000 Subject: [erlang-questions] Converting a string to integer In-Reply-To: References: Message-ID: <7702c0610906011640s4c2b7fa4sf250de26813dceea@mail.gmail.com> On Tue, Jun 2, 2009 at 9:32 AM, Greg Perry wrote: > Ok I have another weird problem. ?I have a file that contains a single > line that is a large number. ?The file is read using read_file with the > second element of the tuple extracted: > > myfile.txt: > 123456 > > element(2,file:read_file("myfile.txt")). > <<"123456"...>> > > Why don't this work? This is a binary not a string (ie. list). You may need to convert it to a list first. -- Rich From ok@REDACTED Tue Jun 2 01:51:53 2009 From: ok@REDACTED (Richard O'Keefe) Date: Tue, 2 Jun 2009 11:51:53 +1200 Subject: [erlang-questions] Adoption of perl/javascript-style regexp syntax In-Reply-To: <19504077.168111243865821581.JavaMail.root@zimbra> References: <19504077.168111243865821581.JavaMail.root@zimbra> Message-ID: <5E8D194E-5314-45AC-A6A9-9EBE874C0657@cs.otago.ac.nz> We have discussed the issue of including other-language syntax in Erlang several times. If I recall correctly, there are several proposals for how one might deal with it, including one of mine which would allow any number of notations without "nesting". In the mean time, may I respectfully point out to something that seems pretty much kindergarten level to me, but doesn't seem to be taught effectively: PROGRAMS ARE DATA. Just because it's source code, that doesn't mean it had to be typed in by a human being. For example, suppose we wanted something like shell here-files. I'll just do the literal case (no substitution) to make my point. ::= ( | )* ::= .{{ .}} ::= A trivial AWK script can recognise this and turn a into a string literal, generating whatever quoting is necessary. All you have to do is write less than a page of AWK (once), and then tell your build tools how to turn .erl-hf files into .erl files. For a non-entirely-unrelated idea, see the UNIX 'xstr(1)' program. From ok@REDACTED Tue Jun 2 02:55:01 2009 From: ok@REDACTED (Richard O'Keefe) Date: Tue, 2 Jun 2009 12:55:01 +1200 Subject: [erlang-questions] Multi-precision math, random number generator entropy, various other questions In-Reply-To: References: Message-ID: <0281602D-DA6C-423A-9A1B-2D6ADBBF89B2@cs.otago.ac.nz> On 1 Jun 2009, at 5:02 am, Greg Perry wrote: > back to February 2008 mentions the problems with Erlang's bignum > libraries and as of R13B this has not yet been fixed: > > http://www.programmersparadox.com/2008/02/05/erlang-integers/ > > Any idea on when, if at any time, Erlang will get robust bignum > support > (including division, power operators etc)? math:pow/2 is EXPLICITLY documented as an interface to the C pow() function. There isn't any bug in integer exponentiation because that function isn't *supposed* to be integer exponentiation. (The last part of the math: manual page says Bugs As these are the C library, the bugs are the same. So you don't expect the math: functions to do ANYTHING that the C functions don't do.) Where did you get the idea that there was a bug in Erlang's integer division? I enclose a 'power' module that computes plain powers (any number to a non-negative integral exponent) and modular powers (integers to non-negative integral exponents modulo some value). Of course it could be improved. The point is that it took 15 minutes to type up and run a few tests. module(power). -export([power/2, modular_power/3]). % power(X, N) raises X to the natural number power N. % For floating point exponents, see math:pow(X, Y). % X itself can be any kind of number. power(X, 0) when is_number(X) -> 1; power(X, N) when is_number(X), is_integer(N), N > 0 -> rpower(X, N). rpower(X, 1) -> X; rpower(X, N) when N band 1 =:= 0 -> rpower(X*X, N bsr 1); rpower(X, N) -> X * rpower(X, N - 1). % modular_power(X, N, M) returns power(X, N) rem M, % except that it keeps on doing remainders as it goes % to keep the intermediate values small. For modular % powers, X must be an integer. modular_power(X, 0, M) when is_integer(X), is_integer(M), M >= 1 -> 1; modular_power(X, N, M) when is_integer(X), is_integer(M), M >= 1, is_integer(N), N > 0 -> rmodular_power(X rem M, N, M). rmodular_power(X, 1, _) -> X; rmodular_power(X, N, M) when N band 1 =:= 0 -> rmodular_power((X * X) rem M, N bsr 1, M); rmodular_power(X, N, M) -> (X * rmodular_power(X, N - 1, M)) rem M. From geoffrey.biggs@REDACTED Tue Jun 2 02:44:33 2009 From: geoffrey.biggs@REDACTED (Geoffrey Biggs) Date: Tue, 02 Jun 2009 09:44:33 +0900 Subject: [erlang-questions] Adoption of perl/javascript-style regexp syntax In-Reply-To: <19504077.168111243865821581.JavaMail.root@zimbra> References: <19504077.168111243865821581.JavaMail.root@zimbra> Message-ID: <4A2475F1.5050701@aist.go.jp> Python provides a method of specifying strings they call "raw strings," which I find quite interesting. Basically, you prefix your string with r or R, and any backslashes are treated as literal characters rather than escape sequences. For example: >>> '\b' '\x08' >>> r'\b' '\\b' More info in the docs: http://docs.python.org/3.0/reference/lexical_analysis.html#string-and-bytes-literals I'm not sure how well it would work in Erlang, but it's certainly useful in Python for avoiding the headache-inducing backslash acrobatics necessary when writing the occasional complex regular expression. Geoff Ulf Wiger wrote: > Dmitrii Dimandt wrote: >> I've just come across re and I like it :) >> >> The only issue I have with it is that I have to specify regexps as >> strings. This leads to ugly-as-hell constucts like these: >> >> {ok, Re} = re:compile("(?> >> It actually tries to find two backslashes there... Or just one? I >> don't know :) What if Erlang could allow this: >> >> Re = /(?> >> ? >> >> Benefits: >> - Less error-prone >> - Expressions written this way can be parsed and compiled by the >> compiler (boost in performance, syntax checked at compile-time) > > > It's not going to boost performance, as this is just > a preprocessor issue. But having to escape the backslashes > when working with regexps is a pain. > > Perhaps a better syntax would be to imitate the > LaTex \verb command. It allows you to specify the > delimiter, and then consumes all chars until it finds > that delimiter, e.g. \verb!gdl4$%\^\$?$! > > Since this exact syntax doesn't work in Erlang, a > slight adjustment is in order. The scanner recognizes > backticks today, but the parser doesn't. So, if we > change the scanner to recognize ` as the Erlang version > of \verb, we can write: > > > 1> re:split("foo\nbar",`!\n!). > [<<"foo">>,<<"bar">>] > > where > > 2> `!\n!. > "\\n" > > > Diff follows. It was a quick hack, so it needs improvement. > > --- /home/uwiger/src/otp/otp_src_R13B/lib/stdlib/src/erl_scan.erl 2009-04-16 05:23:36.000000000 -0400 > +++ erl_scan.erl 2009-06-01 09:09:49.000000000 -0400 > @@ -559,4 +559,2 @@ > tok2(Cs, St, Line, Col, Toks, "^", '^', 1); > -scan1([$`|Cs], St, Line, Col, Toks) -> > - tok2(Cs, St, Line, Col, Toks, "`", '`', 1); > scan1([$~|Cs], St, Line, Col, Toks) -> > @@ -565,2 +563,4 @@ > tok2(Cs, St, Line, Col, Toks, "&", '&', 1); > +scan1([$`|Cs], St, Line, Col, Toks) -> > + scan_verb(Cs, St, Line, Col, Toks, []); > %% End of optimization. > @@ -580,2 +580,27 @@ > > +scan_verb([], _St, Line, Col, Toks, Acc) -> > + {more, {[],Col,Toks,Line,Acc,fun scan_verb/6}}; > +scan_verb([Delim|Cs0], St, Line, Col, Toks, Acc) when Delim =/= $\n, > + Delim =/= $\\ -> > + {Str, Cs, Line1, Col1} = scan_verb_chars( > + Cs0, St, Line, Col, Toks, {Acc,Delim}), > + tok3(Cs, St, Line1, Col1, Toks, string, Str, Str, 0). > + > +scan_verb_chars([], _St, Line, Col, Toks, {Acc, Delim}) -> > + {more, {[], Col, Toks, Line, {Acc,Delim}, fun scan_verb_chars/6}}; > +scan_verb_chars([Delim|Cs], _St, Line, Col, Toks, {Acc, Delim}) -> > + {lists:reverse(Acc), Cs, Line, Col}; > +scan_verb_chars([C|Cs], St, Line, Col, Toks, {Acc, Delim}) when C =/= Delim-> > + {Line1,Col1} = case C of > + $\n -> > + {Line+1, Col}; > + _ -> > + {Line, inc_col(Col,1)} > + end, > + scan_verb_chars(Cs, St, Line1, Col1, Toks, {[C|Acc], Delim}). > + > +inc_col(no_col,_) -> no_col; > +inc_col(C, N) when is_integer(C) -> C+N. > + > + > scan_atom(Cs0, St, Line, Col, Toks, Ncs0) -> > > From ok@REDACTED Tue Jun 2 04:32:20 2009 From: ok@REDACTED (Richard O'Keefe) Date: Tue, 2 Jun 2009 14:32:20 +1200 Subject: [erlang-questions] Breaking out of a foldl In-Reply-To: <14F8BA751CA44C5B8A886C6143BE29BE@SSI.CORP> References: <1c3be50f0905290916r11734dc5k820e86be80f737fe@mail.gmail.com> <14F8BA751CA44C5B8A886C6143BE29BE@SSI.CORP> Message-ID: <960CD761-656C-4F04-A4A3-399EA4ADE0E4@cs.otago.ac.nz> One thing that occurs to me is that the sample code we were shown is so special-purpose that I don't think I'd want to use it. Another thing that occurs to me is that the code was so simple that the point of putting it in the library would have to be the readability advantage of having one shared name that we could all look up in the same place, rather than anything else. Let's see how I would do it. A function is given an accumulator and a new value, and either returns {continue,Acc'} or {stop,Acc'} So early_termination_foldl(_, Acc, []) -> Acc; early_termination_foldl(Fun, Acc0, [X|Xs]) -> case Fun(Acc0, X) of {continue,Acc1} -> early_termination_foldl(Fun, Acc1, Xs) ; {stop,Final} -> Final end. Here we already have a disagreement with the original posting: if the Fun wants to stop with the current accumulator value, it can just return {stop,Acc0}. Why does there need to be a 'break' option just to handle that case? Or of course we could turn the whole thing inside out. xfoldl(_, Acc, []) -> Acc; xfoldl(Fun, Acc0, [X|Xs]) -> Fun(Acc0, X, fun (Acc1) -> xfoldl(Fun, Acc1, Xs) end). Here the Fun "returns {continue,Acc1}" by invoking Continuation(Acc1), and "returns {stop,Final}" by returning Final. [Could this be called bringing a trick out of RABBIT?] So now we have three different versions of the same "early termination foldl", and that's not counting anything using catch/throw (which, pace the friends of Java, comes from the Lisp world with the meaning of "long-distance return", not with the meaning "exception"). I think it's premature to put something in the library before we have a good idea what that something should be. We DON'T have to have agreement about what the BEST thing is, just something that enough people regard as useful and straightforward. (If you got the rather weak joke about RABBIT, you probably think that xfoldl is straightforward...) From ok@REDACTED Tue Jun 2 04:45:14 2009 From: ok@REDACTED (Richard O'Keefe) Date: Tue, 2 Jun 2009 14:45:14 +1200 Subject: [erlang-questions] rberl: parse Java's Resource Bundles in Erlang In-Reply-To: <09037862-DB50-4014-AF32-645F24A32D17@gmail.com> References: <09037862-DB50-4014-AF32-645F24A32D17@gmail.com> Message-ID: <9D52A68D-FF4B-466D-A259-BC60BBE5EBD2@cs.otago.ac.nz> On 30 May 2009, at 12:35 am, Dmitrii Dimandt wrote: > http://github.com/dmitriid/rberl/ > > This is a very small ad-hoc library I threw together to parse Java's > resource bundles. It turns out i like it more than gettext :) > > There's a TODO list on my mind. One question that bugs me is: > > Java's RB's allow stuff like this: > At {2,time,short} on {2,date,long}, we detected {1,number,integer} > spaceships on the planet {0}. > This partly solves a real problem, namely that when you internationalise a message with parameters, the order of the parameters may need to change. UNIX C compilers handle that with the "$" modifier in printf() strings. [Considering that parameters of different types may be different sizes, I have no idea how they make that work.] The residual problem is that the {...} thingies are little programs in a specialised and inadequately powerful language. Consider the that "1 spaceships" is quite simply WRONG in English. So you need to consider singular/non-singular for English. But wait! Some languages have singular (1)/dual (2)/plural (everything else). [Maori does that with pronouns, so if you wanted to include the equivalent of "it/them" in a message, you'd need three cases. Old English did the same.] But wait! Some languages actually have singular/dual/paucal ("a few")/plural. But wait! There are languages where you don't say "N thing(s)" but "N thing(s)", and the numeral classifier depends on what kind of thing. That's all very well until the day that the 'thing' part becomes one of the parameters as well. Suppose that we want tally(N, Thing) -> "There were " and that tally(2, errors) should be "There were 2 'social-lapses' errors" but tally(2, exceptions) should be "There were 2 'events' exceptions". What do Java programmers do about that? Of course, this is just a grossly oversimplified presentation of the problem of generating internationalised messages. But as long as you remember that - a mapping from parameters to messages is a function - functions are data you will be able to see opportunities where Java programmers (should) see obstacles. From vladdu55@REDACTED Tue Jun 2 09:08:34 2009 From: vladdu55@REDACTED (Vlad Dumitrescu) Date: Tue, 2 Jun 2009 09:08:34 +0200 Subject: [erlang-questions] Adoption of perl/javascript-style regexp syntax In-Reply-To: <5E8D194E-5314-45AC-A6A9-9EBE874C0657@cs.otago.ac.nz> References: <19504077.168111243865821581.JavaMail.root@zimbra> <5E8D194E-5314-45AC-A6A9-9EBE874C0657@cs.otago.ac.nz> Message-ID: <95be1d3b0906020008j1620bed2w2b6bdcb65275d3f1@mail.gmail.com> Hi, On Tue, Jun 2, 2009 at 01:51, Richard O'Keefe wrote: > In the mean time, may I respectfully point out to something that > seems pretty much kindergarten level to me, but doesn't seem to > be taught effectively: > > ? ?PROGRAMS ARE DATA. > ........ > A trivial AWK script can recognise this and turn a into > a string literal, generating whatever quoting is necessary. ?All you > have to do is write less than a page of AWK (once), and then tell > your build tools how to turn .erl-hf files into .erl files. As a programmer I like this way of handling this kind of issues because it works now and it's easy. As developer of a source handling tool I can't help but cringe at the prospect of getting requests to support all kinds of homegrown syntaxes... Another problem with external processing of the source files is that it is at the same level as the preprocessor, which many people would like to see replaced with one that understands Erlang code. best regards, Vlad From erlang@REDACTED Tue Jun 2 09:41:47 2009 From: erlang@REDACTED (Joe Armstrong) Date: Tue, 2 Jun 2009 09:41:47 +0200 Subject: [erlang-questions] Breaking out of a foldl In-Reply-To: References: <1c3be50f0905290916r11734dc5k820e86be80f737fe@mail.gmail.com> <14F8BA751CA44C5B8A886C6143BE29BE@SSI.CORP> <4A215C77.2010606@erlang-consulting.com> <9b08084c0906010026r23a245bcy23f586ccbe289696@mail.gmail.com> <401d3ba30906010427l7fe8df0at890dd16752131ae1@mail.gmail.com> <401d3ba30906011144p45133964pae69268778b34138@mail.gmail.com> Message-ID: <9b08084c0906020041w38f913d3lba2c25f96947466@mail.gmail.com> Absolutely - throw is very cheap. The bfoldl/3 function that was suggested is not tail recursive - also we have to pattern match the return value of the Fun at *every* level of recursion. Recall the definition: bfoldl(Fun, Acc0, [Head | Tail]) -> case Fun(Head, Acc0) of {ok, Acc} -> %% 1 bfoldl(Fun, Acc, Tail); {break, _Acc} = Result -> %% 2 Result; break -> {break, Acc0} end; ... In lines 1 and 2 the return value of the Fun being called has to be pattern matched lists:foldl/3 is defined thusly foldl(F, Accu, [Hd|Tail]) -> foldl(F, F(Hd, Accu), Tail); foldl(F, Accu, []) when is_function(F, 2) -> Accu. This is tail recursive so executed with a stack depth of one, whereas bfold/3 executes with a stack depth of the length of the input list. Now we can ask the questions: - which is prettier (code with bfold/3 of code with foldl/3), and - which is faster. I'll write some code to test this. t1(L) sums the lists of the elements in L but breaks the loop if there is some element in the list which is 95000. First the timer code: -module(test1). -compile(export_all). test() -> L = lists:seq(1,100000), T1 = timer:tc(test1, t1, [L]), T2 = timer:tc(test1, t2, [L]), {T1, T2}. Now the functions: t1(L) -> bfoldl(fun f1/2, 0, L). f1(95000, _) -> break; f1(N, A) -> {ok, N + A}. and t2(L) -> (catch lists:foldl(fun f2/2, 0, L)). f2(95000, A) -> throw({break, A}); f2(I, A) -> I + A. Both are three lines - no clear winner in the beauty competition. Now either what this means is clear from the code, or there should be a comment. Timeing: c(test1). {ok,test1} 1> test1:test(). {{12359,{break,4512452500}},{5890,{break,4512452500}}} 2> test1:test(). {{11320,{break,4512452500}},{6231,{break,4512452500}}} The standard library version is twice as fast bfoldl is 260 characters foldl 109 characters /Joe On Mon, Jun 1, 2009 at 9:05 PM, David Mercer wrote: >> Yeah, but it's syntax is somewhat misleading. People with >> Java/C++/Eiffel/etc. background would expect that exceptions should be >> used in exceptional situation, not instead of a return statement >> (which Erlang lacks). > > But throw/1 is not used to throw exceptions: it is used to throw (quoting > from the documentation) "A non-local return from a function." ?That seems to > fit the bill in this case. ?That other languages make throwing expensive > enough to recommend that it only be used in exceptional circumstances is a > restriction on their implementations, not Erlang's. > >> -----Original Message----- >> From: erlang-questions@REDACTED [mailto:erlang-questions@REDACTED] On >> Behalf Of Attila Rajmund Nohl >> Sent: Monday, June 01, 2009 1:44 PM >> To: erlang-questions@REDACTED >> Subject: [erlang-questions] Breaking out of a foldl >> >> 2009/6/1, Joe Armstrong : >> > On Sat, May 30, 2009 at 6:19 PM, Mazen Harake >> > wrote: >> >> Because it is a hack? >> >> >> >> a "fold_until" would be much smoother. >> > >> > Uuugh - smoothness????????????? >> > >> > Why have two functions when one (the existing foldl) is perfectly >> adequate? >> > >> > The use of throw to abnormally terminate a recursion is not a hack. >> > That is what >> > catch-throw was designed to do. exit/1 is for raising errors, throw/1 is >> for >> > abrupt termination of a computation. >> >> Yeah, but it's syntax is somewhat misleading. People with >> Java/C++/Eiffel/etc. background would expect that exceptions should be >> used in exceptional situation, not instead of a return statement >> (which Erlang lacks). >> >> [...] >> > Wirth (the blessed) said something like (paraphrased) every time we >> > add something >> > to a language we should ask *what can we remove*. If we just add stuff >> > to languages >> > (or libraries) - without removing stuff, we add additional complexity >> > so we violate >> > the principle of being as simple as possible. >> > >> > I am often horrified by libraries that offer dozens of different ways >> > to do essentially the >> > same thing - this makes the documentation almost unreadable (since it is >> > unclear >> > which the kernel methods are) and makes learning very difficult. >> > >> > Libraries should provide a small set of primitive parts which can be >> > glued together >> > to solve a large number of problems. If the set of parts is large then >> > learning the library will be very difficult. If you don't know all the >> > functions in a library then >> > programming using the library will be painfully slow since you will >> > have to google >> > your way through large volumes of documentation. >> > >> > If you really really want fold_until then I suggest you make your own >> > personal library >> > (mylib.erl) where you put fold_until (and every other additional >> > function that you think >> > is missing from the standard libraries) - then one day when you are >> > satisfied that >> > your library has proved useful you can publish it. >> > >> > Exactly what should be in the standard libraries is an extremely >> > difficult problem- >> > I think they should contain small sets of orthogonal functions and err >> > on the side >> > of generality. If two function do more of less the same thing one of >> > them should be removed. >> >> I disagree. Every Erlang project I've seen had it's own tracing module >> built on top of dbg. They all had very similar functions that did >> nearly the same thing. This obviously means that the dbg module needs >> a function that simply turns on tracing on a function of a module. >> Yes, it could be done with dbg:tpl, but why shall I type every time >> [{'_',[],[{return_trace}]}] into the shell? Also the equivalent of >> lists:keyfind was probably implemented countless times in most Erlang >> projects. >> >> I do think it's better to have often needed code in the standard >> library. First of all, it's standard, so every programmer should be >> familiar with it. On the other hand the "helper" functions in the >> various mylib libraries are probably not well known to anyone except >> the author. The above mentioned tracing modules had functions doing >> essentially the same, but each with a slightly different syntax which >> is quite annoying. >> >> Using third party libraries (e.g. someone's released mylib) has other >> drawbacks. It might not be useable at all due to licensing. It's an >> other dependency that has to be followed (e.g. when a bugfix release >> comes out). It might not be maintained anymore. It doesn't have the >> same user base as the standard library, so it might have more bugs. >> From the management point of view it's better to work with the >> standard library and in-house code, without 3rd party libraries. >> >> I think that the standard library should first and foremost make >> programming easier. For example, the JTable class in Java has 7 >> constructors. A couple of them probably could be removed to get a more >> minimal code - but the removed code will popup in the applications >> many more times and probably with many more bugs. >> >> ________________________________________________________________ >> erlang-questions mailing list. See http://www.erlang.org/faq.html >> erlang-questions (at) erlang.org > > > ________________________________________________________________ > erlang-questions mailing list. See http://www.erlang.org/faq.html > erlang-questions (at) erlang.org > > From masse@REDACTED Tue Jun 2 09:56:44 2009 From: masse@REDACTED (mats cronqvist) Date: Tue, 02 Jun 2009 09:56:44 +0200 Subject: Breaking out of a foldl In-Reply-To: <401d3ba30906011144p45133964pae69268778b34138@mail.gmail.com> (Attila Rajmund Nohl's message of "Mon\, 1 Jun 2009 20\:44\:01 +0200") References: <1c3be50f0905290916r11734dc5k820e86be80f737fe@mail.gmail.com> <14F8BA751CA44C5B8A886C6143BE29BE@SSI.CORP> <4A215C77.2010606@erlang-consulting.com> <9b08084c0906010026r23a245bcy23f586ccbe289696@mail.gmail.com> <401d3ba30906010427l7fe8df0at890dd16752131ae1@mail.gmail.com> <401d3ba30906011144p45133964pae69268778b34138@mail.gmail.com> Message-ID: <87ab4rysoz.fsf@sterlett.hq.kred> Attila Rajmund Nohl writes: > 2009/6/1, Joe Armstrong : >> On Sat, May 30, 2009 at 6:19 PM, Mazen Harake >> wrote: >>> Because it is a hack? >>> >>> a "fold_until" would be much smoother. >> >> Uuugh - smoothness????????????? >> >> Why have two functions when one (the existing foldl) is perfectly adequate? >> >> The use of throw to abnormally terminate a recursion is not a hack. >> That is what >> catch-throw was designed to do. exit/1 is for raising errors, throw/1 is for >> abrupt termination of a computation. > > Yeah, but it's syntax is somewhat misleading. People with > Java/C++/Eiffel/etc. background would expect that exceptions should be > used in exceptional situation, not instead of a return statement > (which Erlang lacks). Erlang might lack the keyword 'return', but it does have a non-local return construct; 'throw'. Whether or not C++ have problems with that seems quite off-topic here. >> >> Exactly what should be in the standard libraries is an extremely >> difficult problem- >> I think they should contain small sets of orthogonal functions and err >> on the side >> of generality. If two function do more of less the same thing one of >> them should be removed. > > I disagree. Every Erlang project I've seen had it's own tracing module > built on top of dbg. They all had very similar functions that did > nearly the same thing. Perhaps we can agree that keeping the core libraries small, consistent and intuitive is a very good thing (*). Your complaints about dbg is, I think, a different issue; the unwillingness of OTP to add even the most obvious of enhancements to the stdlibs. E.g. the (thankfully no longer) missing string:join function, the lack of which had been discussed for like 15 years before it finally appeared. mats (*) Unfortunately, the current libs fails on all of these; there's way too much cruft (like lists:foldr), they're inconsistent (like string sub_string/substr) and counter-intuitive ( try e.g. lists:seq(2,1)). From masse@REDACTED Tue Jun 2 09:59:53 2009 From: masse@REDACTED (mats cronqvist) Date: Tue, 02 Jun 2009 09:59:53 +0200 Subject: Adoption of perl/javascript-style regexp syntax In-Reply-To: <4A2475F1.5050701@aist.go.jp> (Geoffrey Biggs's message of "Tue\, 02 Jun 2009 09\:44\:33 +0900") References: <19504077.168111243865821581.JavaMail.root@zimbra> <4A2475F1.5050701@aist.go.jp> Message-ID: <8763ffysjq.fsf@sterlett.hq.kred> Geoffrey Biggs writes: > Python provides a method of specifying strings they call "raw > strings," which I find quite interesting. Basically, you prefix your > string with r or R, and any backslashes are treated as literal > characters rather than escape sequences. For example: > >>>> '\b' > '\x08' >>>> r'\b' > '\\b' > > More info in the docs: > http://docs.python.org/3.0/reference/lexical_analysis.html#string-and-bytes-literals > > I'm not sure how well it would work in Erlang, but it's certainly > useful in Python for avoiding the headache-inducing backslash > acrobatics necessary when writing the occasional complex regular > expression. +1 mats From erlang@REDACTED Tue Jun 2 10:16:08 2009 From: erlang@REDACTED (Joe Armstrong) Date: Tue, 2 Jun 2009 10:16:08 +0200 Subject: cocoa bridge? Message-ID: <9b08084c0906020116t792b158ap88e7adaf66eef236@mail.gmail.com> Hi everybody. I am contemplating writing some kind of cocoa thingy and would like to come into contact with some like minded people who are familiar with the mac cocoa stuff. I've been playing with xcode and now want to do all the things I can do in xcode only programmatically. So far I can create windows, add buttons etc programmatically in objective C using the foundation classes. I now need to make a networking top-loop so I can read and write sockets and talk to erlang, and I need a way to programmatically send messages to cocoa objects. Are there any mac experts out there to whom I can send my silly questions - or where are the best forums to ask silly questions? This things I'm interest in are: - programmatic control of foundation classes , cocoa etc. - introspection primitives - socket interfacing (in particular how to interface socket events with the cocoa window top-loop) - nib decompilation and loading Has anybody done anything like this before? I'm after objective C knowledge rather than Erlang knowledge. Cheers /Joe From joelr1@REDACTED Tue Jun 2 10:31:08 2009 From: joelr1@REDACTED (Joel Reymont) Date: Tue, 2 Jun 2009 09:31:08 +0100 Subject: [erlang-questions] cocoa bridge? In-Reply-To: <9b08084c0906020116t792b158ap88e7adaf66eef236@mail.gmail.com> References: <9b08084c0906020116t792b158ap88e7adaf66eef236@mail.gmail.com> Message-ID: <3729C696-B8F3-4D29-9690-D169767D19D7@gmail.com> Joe, On Jun 2, 2009, at 9:16 AM, Joe Armstrong wrote: > - programmatic control of foundation classes , cocoa etc. > - introspection primitives > - socket interfacing (in particular how to interface socket > events with the cocoa window top-loop) > - nib decompilation and loading