Re: [Factor-talk] Macros needed?
I think the key is to use the nth word instead of first and second. Then do it like this: { "a" 2 3 } { "b" 5 6 } 2 random 0 = 0 1 ? rot over [ swap nth ] 2bi@ In your code it would be: dim chart chart-axes vert? 0 1 ? rot over [ swap nth ] 2bi@ Or dim chart chart-axes vert? 0 1 ? [ swap nth ] keep rot nth Or even: dim chart chart-axes vert? 0 1 ? '[ _ swap nth ] bi@ 2017-02-04 2:31 GMT+01:00 Alexander Ilin : > That's great! > > I did this: > > : ?[x/y] ( ? -- quot ) > [ x ] [ y ] ? [ call( a -- b ) ] curry ; inline > > ... > dim chart chart-axes vert? ?[x/y] bi@ > > 04.02.2017, 04:29, "John Benediktsson" : >> Well I'm not sure about the compiler effect declaration, but you could do >> this: >> >> vert? [ x ] [ y ] ? [ call( a -- b ) ] curry >> >>> On Feb 3, 2017, at 5:04 PM, Alexander Ilin wrote: >>> >>> vert? [ x ] [ y ] ? check-effect( a -- b ) >> >> -- >> Check out the vibrant tech community on one of the world's most >> engaging tech sites, SlashDot.org! http://sdm.link/slashdot >> ___ >> Factor-talk mailing list >> Factor-talk@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/factor-talk > > ---=--- > Александр > > -- > Check out the vibrant tech community on one of the world's most > engaging tech sites, SlashDot.org! http://sdm.link/slashdot > ___ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk -- mvh/best regards Björn Lindqvist -- Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] Macros needed?
That's great! I did this: : ?[x/y] ( ? -- quot ) [ x ] [ y ] ? [ call( a -- b ) ] curry ; inline ... dim chart chart-axes vert? ?[x/y] bi@ 04.02.2017, 04:29, "John Benediktsson" : > Well I'm not sure about the compiler effect declaration, but you could do > this: > > vert? [ x ] [ y ] ? [ call( a -- b ) ] curry > >> On Feb 3, 2017, at 5:04 PM, Alexander Ilin wrote: >> >> vert? [ x ] [ y ] ? check-effect( a -- b ) > > -- > Check out the vibrant tech community on one of the world's most > engaging tech sites, SlashDot.org! http://sdm.link/slashdot > ___ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk ---=--- Александр -- Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] Macros needed?
Well I'm not sure about the compiler effect declaration, but you could do this: vert? [ x ] [ y ] ? [ call( a -- b ) ] curry > On Feb 3, 2017, at 5:04 PM, Alexander Ilin wrote: > > vert? [ x ] [ y ] ? check-effect( a -- b ) -- Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] Macros needed?
Hi, John! The trouble in my case is -- I'd have to specify the stack effect for a call that's hidden deep inside the bi@ implementation. I'm trying to refrain from inventing my own implementation of `bi@(`. Is there a way to tell the compiler about the effect of a quotation on stack, so it would perform the run-time check, and take that into consideration for the further analysis? Something like this: vert? [ x ] [ y ] ? check-effect( a -- b ) bi@ Is there a way to teach the compiler that both input quotations to the `?` have the same stack effect, therefore it wouldn't matter for the analysis which one is selected. Bjourne? 04.02.2017, 03:42, "John Benediktsson" :You just need to tell Factor the expected stack effect. See, this fails to compile, because the quotation is only selected at run-time and the compiler isn't smart enough to examine both: : foo ( seq -- seq' ) dup length even? [ 1 - ] [ 2 + ] ? map ; But, you can always do something like this where you tell Factor to call the quotation with the expected stack effect: : foo ( seq -- seq' ) dup length even? [ 1 - ] [ 2 + ] ? '[ _ call( elt -- elt' ) ] map ; I think that might incur some run-time performance penalties because it would check the stack effect on every call, which doesn't matter for your use-case, but might if it was inside a hot loop. Best,John. On Fri, Feb 3, 2017 at 4:25 PM, Alexander Ilinwrote:Hello! I'm developing my chart gadget. I want to achieve this:ALIAS: x firstALIAS: y second: chart-axes ( chart -- seq ) [ dim>> ] [ axes>> ] bi [ nip ] [ [ 0 swap 2array ] map ] if* ;M: axis draw-gadget* dup parent>> dup chart? [| axis chart | axis vertical?>> :> vert? chart dim>> :> dim dim chart chart-axes vert? [ [ x ] bi@ ] [ [ y ] bi@ ] if ! etc... ] [ 2drop ] if ; I thought I found a clever way to simplify that `if` there: dim chart chart-axes vert? [ x ] [ y ] ? bi@ But the compiler says that I can't use `call` on runtime-computed quotations. Is there a way to work around that, like, by using a MACRO: or something? Or is this a hard limitation on the available abstraction of the computation? Basically, depending on a boolean flag I need to either take the first or the second element of the two arrays on the stack, and place the taken elements on the stack in the same order.---=--- Александр--Check out the vibrant tech community on one of the world's mostengaging tech sites, SlashDot.org! http://sdm.link/slashdot___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk,--Check out the vibrant tech community on one of the world's mostengaging tech sites, SlashDot.org! http://sdm.link/slashdot,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk ---=---Александр -- Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] Macros needed?
You just need to tell Factor the expected stack effect. See, this fails to compile, because the quotation is only selected at run-time and the compiler isn't smart enough to examine both: : foo ( seq -- seq' ) dup length even? [ 1 - ] [ 2 + ] ? map ; But, you can always do something like this where you tell Factor to call the quotation with the expected stack effect: : foo ( seq -- seq' ) dup length even? [ 1 - ] [ 2 + ] ? '[ _ call( elt -- elt' ) ] map ; I think that might incur some run-time performance penalties because it would check the stack effect on every call, which doesn't matter for your use-case, but might if it was inside a hot loop. Best, John. On Fri, Feb 3, 2017 at 4:25 PM, Alexander Ilin wrote: > Hello! > > I'm developing my chart gadget. I want to achieve this: > > ALIAS: x first > ALIAS: y second > > : chart-axes ( chart -- seq ) > [ dim>> ] [ axes>> ] bi [ > nip > ] [ > [ 0 swap 2array ] map > ] if* ; > > > M: axis draw-gadget* > dup parent>> dup chart? [| axis chart | > axis vertical?>> :> vert? > chart dim>> :> dim > dim chart chart-axes vert? [ [ x ] bi@ ] [ [ y ] bi@ ] if > ! etc... > ] [ 2drop ] if ; > > I thought I found a clever way to simplify that `if` there: > > dim chart chart-axes vert? [ x ] [ y ] ? bi@ > > But the compiler says that I can't use `call` on runtime-computed > quotations. Is there a way to work around that, like, by using a MACRO: or > something? > > Or is this a hard limitation on the available abstraction of the > computation? > > Basically, depending on a boolean flag I need to either take the first > or the second element of the two arrays on the stack, and place the taken > elements on the stack in the same order. > > ---=--- > Александр > > > -- > Check out the vibrant tech community on one of the world's most > engaging tech sites, SlashDot.org! http://sdm.link/slashdot > ___ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk > -- Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
[Factor-talk] Macros needed?
Hello! I'm developing my chart gadget. I want to achieve this: ALIAS: x first ALIAS: y second : chart-axes ( chart -- seq ) [ dim>> ] [ axes>> ] bi [ nip ] [ [ 0 swap 2array ] map ] if* ; M: axis draw-gadget* dup parent>> dup chart? [| axis chart | axis vertical?>> :> vert? chart dim>> :> dim dim chart chart-axes vert? [ [ x ] bi@ ] [ [ y ] bi@ ] if ! etc... ] [ 2drop ] if ; I thought I found a clever way to simplify that `if` there: dim chart chart-axes vert? [ x ] [ y ] ? bi@ But the compiler says that I can't use `call` on runtime-computed quotations. Is there a way to work around that, like, by using a MACRO: or something? Or is this a hard limitation on the available abstraction of the computation? Basically, depending on a boolean flag I need to either take the first or the second element of the two arrays on the stack, and place the taken elements on the stack in the same order. ---=--- Александр -- Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk