Hello,
Sorry for bad english,
I am a newbie in factor,
came from common-lisp fields.
I've tried to implement bubble-sort, and got error i cannot deal with for few
hours.
Can someone please help?
Sorry for maybe weird and not true-factor-way code:
:: bubble-sort! ( seq cmp -- sorted-seq )
seq [ dup 0 = [ drop drop ] [
swap over 1 - seq nth cmp [ :> j!
[ j 0 > [ j j 1 - [ seq nth ] bi@ < ] [ f ] if ] [
j j 1 - seq exchange j 1 - j!
] while
] [ drop ] if
] if
] each-index seq ;
The error is:
The input quotations to "if" don't match their expected effects
Input Expected
Got
[ drop drop ] (( ..a --
..b )) (( x x -- ))
[ _ _ 2 load-locals swap over 1 - -1 get-local nth 0 get-local... (( ..a --
..b )) (( x x -- x x ))
And second, as you can see i've used that construction: j 0 > [ j j 1 - [ seq
nth ] bi@ < ] [ f ] if
as analog for binary lazy left-to-right `and'. It's because standart Factor
`and' operators are working just with booleans from stack. So im interested
whats an idiomatic way to do things like this? Maybe it could be useful to have
lazy left-to-right logical operators that work on quotations in standart
library?
Thanks.
Ander
------------------------------------------------------------------------------
This SF.net email is sponsored by
Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk