Re: What's up with %MY?
"Bryan C. Warnock" <[EMAIL PROTECTED]> wrote: > On Thursday 06 September 2001 08:53 am, Dave Mitchell wrote: > > But surely %MY:: allows you to access/manipulate variables that are in > > scope, not just variables are defined in the current scope, ie > > > > my $x = 100; > > { > > print $MY::{'$x'}; > > } > > > > I would expect that to print 100, not 'undef'. Are your expectations > > different? > > Yes. I would expect that to print 'undef'. '$x' doesn't exist as a key in > %MY:: > > > > > I think any further discussion hinges on that. > > Yes. My expectations are different. My expectations are exactly like my > previous PATH example. > > my $x = 100; > { > $MY::{'$x'} = 200; # Equivalent to 'my $x = 200' > print $x; > } > print $x; > > That should print 200, and 100, should it not? > You are creating a lexical in the current scope, and assigning it the value > of 200. You are not finding a currently existing $x and assigning it the > value of 200, resulting in 200 / 200. > > But let's be a little more pragmatic about it, shall we? Look beyond the > fire and brimstone for a moment. As Dan said, we can already screw up your > entire world. So other than a couple clever hacks from Damian, how will > they be used? I think you're confusing me with Ken Fox! At the moment, I'm just trying to eke out of Damian what the precise semnatics of %MY:: will be, since there are lots of possibilities. I'll join Ken in the Hellfire and Damnation stakes after I've got a fixed target to aim at ;-) Okay, personally I like the idea that %MY:: doesn't affect the values or visibility (much) of outer scopes, since there's less action-at-a-distance going on. The main drawback is that users may find it counter-intuitive that you can't substitute $x in an expression with %MY::{'$x'} and get the same result. But I guess they'll just have to read the man page properly :-) Anyway, in any particular scope, a variable $x can be in one of three states: A) not defined, so '$x' refers to an outer lexical or global B) defined but not introduced, and '$x' similarly refers to the outer value (if any) C) defined and introduced; '$x' refers to the local value. Any manipulation of $::MY{'$x'} at compile or run time will have certain effects in each of those 3 cases. Here's what I think all the permuations should be. ... = %::MY{'$x'} - A,B: returns undef; C: returns ref to $x. In no case is $x autovivified. %::MY{'$x'} = \... --- A@compile: equivalent of "my $x=..." A@run: probably equivalent to "my $x=...", but we need to decide if affects the visibility of previously compiled references to $x: $x = 1; # package var sub f { caller().{MY}{'$x'} = 2 if $_[0] } sub g { f(1); $x; # does this see the lexical or the package var? } B,C: sets the lexical '$x' to the new value delete %MY::{'$x'} -- A,B: NOOP C: marks the lexical as deleted. Any subsequent "...=$x" or "$x=..." give a runtime error; subsequent "...=%MY::{'$x'} returns undef, while a subsequent "%MY::{'$x'}=..." resurrects the variable with a new value.
Math functions? (Particularly transcendental ones)
Okay, I'm whipping together the "fancy math" section of the interpreter assembly language. I've got: sin, cos, tan : Plain ones asin, acos, atan: arc-whatevers shinh, cosh, tanh : Hyperbolic whatevers log2, log10, log: Base 2, base 10, and explicit base logarithms pow : Raise x to the y power Can anyone think of things I've forgotten? It's been a while since I've done numeric work. Dan --"it's like this"--- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk
Re: Math functions? (Particularly transcendental ones)
> "DS" == Dan Sugalski <[EMAIL PROTECTED]> writes: DS> Okay, I'm whipping together the "fancy math" section of the interpreter DS> assembly language. I've got: DS> sin, cos, tan : Plain ones DS> asin, acos, atan : arc-whatevers DS> shinh, cosh, tanh : Hyperbolic whatevers DS> log2, log10, log : Base 2, base 10, and explicit base logarithms DS> pow : Raise x to the y power DS> Can anyone think of things I've forgotten? It's been a while since I've DS> done numeric work. i am not being picky, but there is secant, and arc hyperbolics too. you can derive secant from the others (gack, i forget how!) but then tan is just sin/cos and that is usually supplied anyway. some langs have exp which is just pow( e, power ). what about providing e and pi as builtin functions with controllable precision. they would return a float or a bigfloat depending on the precision requested. with no args they would return a float with maximal precision for that size. how complete do you want this? why make it built in and not a math module with its own op codes? and i would think math is low priority right now and would rather see you spend your valuable time on more generic and critical parrot stuff. this information comes from an echelon profile of your keyboard input. :) uri -- Uri Guttman - [EMAIL PROTECTED] -- http://www.sysarch.com SYStems ARCHitecture and Stem Development -- http://www.stemsystems.com Search or Offer Perl Jobs -- http://jobs.perl.org
Re: Math functions? (Particularly transcendental ones)
Dan Sugalski <[EMAIL PROTECTED]> writes: > Okay, I'm whipping together the "fancy math" section of the interpreter > assembly language. I've got: > Can anyone think of things I've forgotten? It's been a while since I've > done numeric work. Uri mentioned exp(x) = e^x, but I think if you are going to include log2, log10, log, etc, you should also include ln.
Re: Math functions? (Particularly transcendental ones)
At 12:12 PM 9/8/2001 -0400, Uri Guttman wrote: > > "DS" == Dan Sugalski <[EMAIL PROTECTED]> writes: > DS> Can anyone think of things I've forgotten? It's been a while since > I've > DS> done numeric work. > >i am not being picky, but there is secant, and arc hyperbolics too. you >can derive secant from the others (gack, i forget how!) but then tan is >just sin/cos and that is usually supplied anyway. some langs have exp >which is just pow( e, power ). Secant in it's variations, along with the arc hyperbolics are now in. As is exp. >what about providing e and pi as builtin functions with controllable >precision. they would return a float or a bigfloat depending on the >precision requested. with no args they would return a float with maximal >precision for that size. Good idea. We'll do that. >how complete do you want this? why make it built in and not a math >module with its own op codes? They strike me as a reasonable set of things to have. They don't, I suppose, have to be part of the base opcode set. >and i would think math is low priority right now and would rather see >you spend your valuable time on more generic and critical parrot >stuff. this information comes from an echelon profile of your keyboard >input. :) Ah, I'm not actually going to write these, just get them in the documentation. Not that writing them is tough--for example, the entire opcode function to take the tangent of an NV constant is: AUTO_OP tan_n_nc { NUM_REG(P1) = tan(P2); } which, as you would probably admit, isn't that tough. :) (There's actually more text in the support files than in the actual source module) Besides, this stuff's quick and satisfying to whip out while I'm debugging annoying memory allocation problems. It's nice to have simple things to do that will work first time... Dan --"it's like this"--- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk
Re: Math functions? (Particularly transcendental ones)
At 12:29 PM 9/8/2001 -0400, Buddha Buck wrote: >Dan Sugalski <[EMAIL PROTECTED]> writes: > > > Okay, I'm whipping together the "fancy math" section of the interpreter > > assembly language. I've got: > > > > > Can anyone think of things I've forgotten? It's been a while since I've > > done numeric work. > >Uri mentioned exp(x) = e^x, but I think if you are going to include >log2, log10, log, etc, you should also include ln. Added. Dan --"it's like this"--- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk
Re: Math functions? (Particularly transcendental ones)
On Saturday 08 September 2001 12:00 pm, Dan Sugalski wrote: > Okay, I'm whipping together the "fancy math" section of the interpreter > assembly language. I've got: > > sin, cos, tan : Plain ones > asin, acos, atan : arc-whatevers > shinh, cosh, tanh : Hyperbolic whatevers > log2, log10, log : Base 2, base 10, and explicit base logarithms > pow : Raise x to the y power > > Can anyone think of things I've forgotten? It's been a while since I've > done numeric work. > 1/x is often handy, although maybe not enough to justify its own opcode. (It is often used in other calculations, however, so perhaps one opcode would be better than 3.) sqrt has traditionally been provided in languages, although it (and all other roots) could simply be an power (inverse x). atan2 is also often traditionally provided in a language, since it identifies the proper quadrant. Others would include abs, floor, ceil, round, mod - don't know if those are basic or "fancy" to you. I suspect you may have those already The question arises what do you do as its opcode, and what languages features can be a series of opcodes. -- Bryan C. Warnock [EMAIL PROTECTED]
Re: Math functions? (Particularly transcendental ones)
At 01:38 PM 9/8/2001 -0400, Bryan C. Warnock wrote: >On Saturday 08 September 2001 12:00 pm, Dan Sugalski wrote: > > Okay, I'm whipping together the "fancy math" section of the interpreter > > assembly language. I've got: > > > > sin, cos, tan : Plain ones > > asin, acos, atan : arc-whatevers > > shinh, cosh, tanh : Hyperbolic whatevers > > log2, log10, log : Base 2, base 10, and explicit base logarithms > > pow : Raise x to the y power > > > > Can anyone think of things I've forgotten? It's been a while since I've > > done numeric work. > > > >1/x is often handy, although maybe not enough to justify its own opcode. >(It is often used in other calculations, however, so perhaps one opcode >would be better than 3.) > >sqrt has traditionally been provided in languages, although it (and all >other roots) could simply be an power (inverse x). > >atan2 is also often traditionally provided in a language, since it >identifies the proper quadrant. Fair enough. Those are all going into the transcendental section, I think. (Though my very vague memories of trig makes me think they're not, strictly speaking, transcendental functions) >Others would include abs, floor, ceil, round, mod - don't know if those are >basic or "fancy" to you. I suspect you may have those already Basic. No polynomial expansions under the hood means basic. :) I added mod, I forgot the rest. >The question arises what do you do as its opcode, and what languages >features can be a series of opcodes. Well, it looks like perl's angling to make things easier for the math folks, so it makes sense to have these as single opcodes. (If anyone can think of things that'd help out the bioperl people, let me know--we can add a set of "bioperl ops" ) I'm beginning to think that Uri's right, and the transcendental bits should be in a separate module. No need to yank in the math libraries ('specially the system math libraries) if you're just doing text processing. Of course, that means I need to define the ops to load in op modules... Dan --"it's like this"--- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk
Re: Math functions? (Particularly transcendental ones)
On Sat, Sep 08, 2001 at 12:00:24PM -0400, Dan Sugalski wrote: > pow : Raise x to the y power You forgot biff, zap and womp! -- Michael G. Schwern <[EMAIL PROTECTED]>http://www.pobox.com/~schwern/ Perl6 Quality Assurance <[EMAIL PROTECTED]> Kwalitee Is Job One stretch your colon out, put some effort into it, and shit through that paste. -- japhy
Re: Math functions? (Particularly transcendental ones)
> "DS" == Dan Sugalski <[EMAIL PROTECTED]> writes: >> 1/x is often handy, although maybe not enough to justify its own opcode. >> (It is often used in other calculations, however, so perhaps one opcode >> would be better than 3.) >> >> sqrt has traditionally been provided in languages, although it (and all >> other roots) could simply be an power (inverse x). >> >> atan2 is also often traditionally provided in a language, since it >> identifies the proper quadrant. DS> Fair enough. Those are all going into the transcendental section, DS> I think. (Though my very vague memories of trig makes me think DS> they're not, strictly speaking, transcendental functions) >> Others would include abs, floor, ceil, round, mod - don't know if >> those are basic or "fancy" to you. I suspect you may have those >> already DS> Basic. No polynomial expansions under the hood means basic. :) I DS> added mod, I forgot the rest. some of those are in POSIX now. will they be standard in the math lib? will the math lib be autoloaded upon detection of any of its functions? we don't want to have to say use math; all the time. >> The question arises what do you do as its opcode, and what >> languages features can be a series of opcodes. DS> Well, it looks like perl's angling to make things easier for the DS> math folks, so it makes sense to have these as single opcodes. (If DS> anyone can think of things that'd help out the bioperl people, let DS> me know--we can add a set of "bioperl ops" ) since it will be a separate lib, expanding it will be easier and less of an issue. we just have to define the official names and ops supported in it. i am sure math types will want many more functions but those will have to be in another module and loaded explicitly with a use command. DS> I'm beginning to think that Uri's right, and the transcendental DS> bits should be in a separate module. No need to yank in the math DS> libraries ('specially the system math libraries) if you're just DS> doing text processing. i forgot about the c lib not being needed then. that is a good win too. DS> Of course, that means I need to define the ops to load in op DS> modules... see, i said you weren't focusing on the more general stuff. but then hacking the math stuff made you realize that. i think we have to keep a shorter leash on you. :) speaking of those loading ops, i don't recall any discussions about that yet. we have covered some of the format for the op code tables, but the actual loading and what ops do it and how they do it is still open IMO. i am sure you can hack something up quickly but this will be a critical area as we will be loading more modules than with perl5 it seems. uri -- Uri Guttman - [EMAIL PROTECTED] -- http://www.sysarch.com SYStems ARCHitecture and Stem Development -- http://www.stemsystems.com Search or Offer Perl Jobs -- http://jobs.perl.org
Re: Math functions? (Particularly transcendental ones)
> "MGS" == Michael G Schwern <[EMAIL PROTECTED]> writes: MGS> On Sat, Sep 08, 2001 at 12:00:24PM -0400, Dan Sugalski wrote: >> pow: Raise x to the y power MGS> You forgot biff, zap and womp! zap is an ibm 360/370/390 assembler op code and i bet they trademarked/patented/whatevered its name. :) Zero and Add Packed. gawd, i can't believe i remembered that. i don't recall exactly what it does but i think it was decimal math (packed decimal). uri -- Uri Guttman - [EMAIL PROTECTED] -- http://www.sysarch.com SYStems ARCHitecture and Stem Development -- http://www.stemsystems.com Search or Offer Perl Jobs -- http://jobs.perl.org
Re: Math functions? (Particularly transcendental ones)
On Sat, Sep 08, 2001 at 02:55:36PM -0400, Uri Guttman wrote: > zap is an ibm 360/370/390 assembler op code and i bet they > trademarked/patented/whatevered its name. :) > > Zero and Add Packed. > > gawd, i can't believe i remembered that. i don't recall exactly what it > does but i think it was decimal math (packed decimal). >From The Free On-line Dictionary of Computing (06 Jun 01) [foldoc]: Zero and Add Packed (ZAP) An {IBM 360}/370 {assembly language} instruction used when performing {packed arithmatic} to initialise an {accumulator}. -- Michael G. Schwern <[EMAIL PROTECTED]>http://www.pobox.com/~schwern/ Perl6 Quality Assurance <[EMAIL PROTECTED]> Kwalitee Is Job One Ooops, fatal mutation in the test script.
Re: Math functions? (Particularly transcendental ones)
On Sat, 2001-09-08 at 11:00, Dan Sugalski wrote: > Okay, I'm whipping together the "fancy math" section of the interpreter > assembly language. I've got: > > sin, cos, tan : Plain ones > asin, acos, atan : arc-whatevers > shinh, cosh, tanh : Hyperbolic whatevers > log2, log10, log : Base 2, base 10, and explicit base logarithms > pow : Raise x to the y power > > Can anyone think of things I've forgotten? It's been a while since I've > done numeric work. > > Dan > While not math, per se, there are bitops (and, or, not, xor, eqv) and shifts (though they can be simulated by "mul tx,ty,(2^bits)" and "div tx,ty,(2^bits)") I doubt rolls would be useful :) Are there going to be string ops as well, or would add and mul work on string registers? Brian
Re: Math functions? (Particularly transcendental ones)
On Saturday 08 September 2001 04:14 pm, Brian Wheeler wrote: > While not math, per se, there are bitops (and, or, not, xor, eqv) and > shifts (though they can be simulated by "mul tx,ty,(2^bits)" and "div > tx,ty,(2^bits)") There will be bitops. > > I doubt rolls would be useful :) Vuja de. > > Are there going to be string ops as well, or would add and mul work on > string registers? Yes. -- Bryan C. Warnock [EMAIL PROTECTED]
Re: Math functions? (Particularly transcendental ones)
--- Dan Sugalski <[EMAIL PROTECTED]> wrote: > Okay, I'm whipping together the "fancy math" section of > the interpreter > assembly language. I've got: > > sin, cos, tan : Plain ones > asin, acos, atan : arc-whatevers > shinh, cosh, tanh : Hyperbolic whatevers > log2, log10, log : Base 2, base 10, and explicit base > logarithms > pow : Raise x to the y power > > Can anyone think of things I've forgotten? It's been a > while since I've > done numeric work. ln, asinh, acosh, atanh2? -- BKS __ Do You Yahoo!? Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger http://im.yahoo.com
Re: Math functions? (Particularly transcendental ones)
> "JH" == Jeremy Howard <[EMAIL PROTECTED]> writes: JH> Uri Guttman wrote: >> > "BS" == Benjamin Stuhl <[EMAIL PROTECTED]> writes: >> >> >> Can anyone think of things I've forgotten? It's been a while since >> >> I've done numeric work. >> BS> ln, asinh, acosh, atanh2? >> >> dan mentioned log (base anything) but i don't recall ln. and definitely >> the arc hyberbolics are in after i pointed them out. dunno about atanh2. >> JH> We only really need ln(). Then [log(y) base x] is simply [ln(y)/ln(x)]. JH> There's no need to have separate functions for different bases. then there is no need for tan, or secant, or many others. it is useful to have some functions map directly to math lib calls. it usually is faster (fewer ops to call) and sometimes more accurate. we have pow and dan said will will probably have exp too. same thing. having these extra ops costs almost nothing and will simplify code generation and support of multiple language frontends. keep in mind parrot's goal is beyond just supporting perl5 functions. there is no reason why we can't support most common math functions in their most useful forms and not be minimal and have only 1 ln function. we can have ln, log2, log10 and log (any base) all at the same time. uri -- Uri Guttman - [EMAIL PROTECTED] -- http://www.sysarch.com SYStems ARCHitecture and Stem Development -- http://www.stemsystems.com Search or Offer Perl Jobs -- http://jobs.perl.org
Re: Math functions? (Particularly transcendental ones)
> "BS" == Benjamin Stuhl <[EMAIL PROTECTED]> writes: >> Can anyone think of things I've forgotten? It's been a while since >> I've done numeric work. BS> ln, asinh, acosh, atanh2? dan mentioned log (base anything) but i don't recall ln. and definitely the arc hyberbolics are in after i pointed them out. dunno about atanh2. uri -- Uri Guttman - [EMAIL PROTECTED] -- http://www.sysarch.com SYStems ARCHitecture and Stem Development -- http://www.stemsystems.com Search or Offer Perl Jobs -- http://jobs.perl.org