Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

To-pair vs as-pair

 [1/4] from: reboler::ifrance::com at: 1-Jan-2003 17:16


Hi list, Reading the new document about the Draw dialect, I found a new function 'as-pair. May be not so new for some of you, but in case... Compared to 'to-pair, 'as-pair seems much easier to work with: ; direct value
>> as-pair 2 5
== 2x5 ; variables
>> x: 3
== 3
>> as-pair x x * 2
== 3x6
>> as-pair x 2 * x
== 3x6
>> to-pair 2 5
== 5
>> to-pair [2 5]
== 2x5
>> to-pair reduce [x x * 2]
== 3x6 Regards Patrick _____________________________________________________________________ GRAND JEU SMS : Pour gagner un NOKIA 7650, envoyez le mot IF au 61321 (prix d'un SMS + 0.35 euro). Un SMS vous dira si vous avez gagné. Règlement : http://www.ifrance.com/_reloc/sign.sms

 [2/4] from: anton:lexicon at: 2-Jan-2003 11:24


Yes, as-pair is quite useful. Keep in mind that if you use these functions in a tight loop that draws some graphics, for example, you can get some speed by gutting the functions. Let's look at the sources:
>> ?? as-pair
as-pair: func [ "Combine X and Y values into a pair." x [number!] y [number!] ][ to-pair reduce [to-integer x to-integer y] ]
>> ?? to-pair
to-pair: func ["Converts to pair value." value "Value to convert"][to pair! :value] You can see that as-pair makes three mezzanine function calls. This will slow you down in a tight loop, so instead, you could just do everything yourself: to pair! reduce [to integer! x to integer! y] That will be much faster. (And also backwards compatible to last full version of view 1.2.1) Anton.

 [3/4] from: nitsch-lists:netcologne at: 2-Jan-2003 4:30


Anton wrote:
>Yes, as-pair is quite useful. >Keep in mind that if you use these >functions in a tight loop that draws >some graphics, for example, you can >
[snip]
> >You can see that as-pair makes three mezzanine function calls. >This will slow you down in a tight loop, so instead, >you could just do everything yourself: > > to pair! reduce [to integer! x to integer! y] >That will be much faster. >(And also backwards compatible to last full version of view 1.2.1) >
if speed matters i would drop the reduce p: 0x0 p/x: 3.8 p/y: 5.3 probe p in an expression you can use p2: (p: 0x0 p/x: 3.8 p/y: 5.3 p)

 [4/4] from: rebol-list2:seznam:cz at: 3-Jan-2003 11:54


Hello Anton, Thursday, January 2, 2003, 1:24:52 AM, you wrote: A> Yes, as-pair is quite useful. A> Keep in mind that if you use these A> functions in a tight loop that draws A> some graphics, for example, you can A> get some speed by gutting the functions. A> Let's look at the sources:
>>> ?? as-pair
A> as-pair: func [ A> "Combine X and Y values into a pair." A> x [number!] y [number!] A> ][ A> to-pair reduce [to-integer x to-integer y] A> ] A> You can see that as-pair makes three mezzanine function calls. A> This will slow you down in a tight loop, so instead, A> you could just do everything yourself: A> to pair! reduce [to integer! x to integer! y] A> That will be much faster. When you are talking about that, I wonder why RT uses the slower to-pair and to-integer in such a functions... =( Oliva David )=======================( [oliva--david--seznam--cz] )== =( Earth/Europe/Czech_Republic/Brno )============================= =( coords: [lat: 49.22 long: 16.67] )=============================