Hi, I've been trying to figure out how to code in Factor. I made a trivial
vocabulary (a temperature converter) to try and figure a few things out. It
runs fine in the listener but when deployed with deploy-tool it fails. The
error message suggests die was called and if I didn't call it (which I
didn't AFAIK) there is a problem with Factor itself. I'm running Mac OS X
10.5.6. I'm not certain which version of Factor, the About Factor box only
says 'Factor' so consider that a second bug report.
The code I'm running is:
--------------------------------------------------------------------------------------
USING: io kernel sequences math.parser combinators math
prettyprint ;
IN: tests.temperature-converter
: print-unit-request ( -- )
"Enter the temperature system to convert from " write
"(C/F) or 0 to exit:" write ;
: get-unit ( -- char ) readln first ;
: request-unit ( -- char ) print-unit-request get-unit ;
DEFER: get-correct-unit
: get-correct-unit ( -- char ) request-unit
{
{ [ dup [ CHAR: c = ] [ CHAR: C = ] bi or ] [ drop 1 ] }
{ [ dup [ CHAR: f = ] [ CHAR: F = ] bi or ] [ drop 2 ] }
{ [ dup CHAR: 0 = ] [ drop 0 "Exiting!" print ] }
[ drop "Incorrect unit!" print get-correct-unit ]
} cond ;
: print-temp-request ( -- )
"Enter the temperature to convert:" write ;
: get-temp ( -- num ) readln string>number ;
: request-temp ( -- num ) print-temp-request get-temp ;
DEFER: get-correct-temp
: get-correct-temp ( -- num ) request-temp dup number? [ ]
[ drop "Invalid temperature!" print get-correct-temp ] if ;
: c-to-f ( num -- num ) 9 * 5 / 32 + ;
: f-to-c ( num -- num ) 32 - 5 * 9 / ;
: output-temp ( num num -- ) swap
{
{ [ dup 1 = ]
[ drop "The temperature in Fahrenheit is " write . ] }
{ [ dup 2 = ]
[ drop "The temperature in Celsius is " write . ] }
[ drop drop "Error!" print ]
} cond ;
: run-temp-con ( -- ) get-correct-unit
{
{ [ dup 1 = ] [ get-correct-temp c-to-f output-temp ] }
{ [ dup 2 = ] [ get-correct-temp f-to-c output-temp ] }
[ drop ]
} cond ;
MAIN: run-temp-con
--------------------------------------------------------------------------------------
My attempt to run it from the CLI went
Gareth - /Applications/factor/temperature-converter.app/Contents/MacOS
: ./tests.temperature-converter
Enter the temperature system to convert from (C/F) or 0 to exit:c
Enter the temperature to convert:7
The temperature in Fahrenheit is The die word was called by the library.
Unless you called it yourself,
you have triggered a bug in Factor. Please report.
Starting low level debugger...
Basic commands:
q -- continue executing Factor - NOT SAFE
im -- save image to fep.image
x -- exit Factor
Advanced commands:
d <addr> <count> -- dump memory
u <addr> -- dump object at tagged <addr>
. <addr> -- print object at tagged <addr>
t -- toggle output trimming
s r -- dump data, retain stacks
.s .r .c -- print data, retain, call stacks
e -- dump environment
g -- dump generations
card <addr> -- print card containing address
addr <card> -- print address containing card
data -- data heap dump
words -- words dump
tuples -- tuples dump
refs <addr> -- find data heap references to object
push <addr> -- push object on data stack - NOT SAFE
code -- code heap dump
READY
x
------------------------------------------------------------------------------
------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises
looking to deploy the next generation of Solaris that includes the latest
innovations from Sun and the OpenSource community. Download a copy and
enjoy capabilities such as Networking, Storage and Virtualization.
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk