Hi Morgan,
You're using the ``.'' word which is part of the prettyprinter. By
default this vocabulary is not deployed. You can choose to deploy
with it by running ``"tests.temperature-converter" deploy-tool'' and
selecting this option. Alternately, you don't really need the ``.''
word -- you can use ``number>string print'' instead and deploy without
prettyprinting.
Another thing I noticed is that you're not calling ``flush'', so
output might not be printed to screen and the user will be left
wondering what's happening.
Here's a way you could write the program without using prettyprint:
USING: ascii combinators io kernel math math.parser sequences
summary ;
IN: temp2
ERROR: bad-unit string ;
M: bad-unit summary
drop "Please enter ``C'' or ``F'' next time." ;
: prompt-unit ( -- string )
"Enter the temperature system to convert from (C/F) or 0 to exit: "
write flush readln [ blank? ] trim >lower
dup { "c" "f" } member? [ bad-unit ] unless ;
ERROR: bad-number n ;
M: bad-number summary
drop "Please enter a number next time." ;
: prompt-temperature ( -- n )
"Enter the temperature to convert: " write flush
readln string>number dup [ bad-number ] unless ;
: c-to-f ( num -- num ) 9 * 5 / 32 + ;
: f-to-c ( num -- num ) 32 - 5 * 9 / ;
: output-temperature ( string n -- )
swap {
{ "c" [ "The temperature in Fahrenheit is " write c-to-f
number>string p
rint ] }
{ "f" [ "The temperature in Celsius is " write f-to-c
number>string prin
t ] }
[ 2drop "Error: enter C/F on the first line, then a number"
print ]
} case ;
: run-temp ( -- )
prompt-unit
prompt-temperature
output-temperature ;
MAIN: run-temp
Have fun,
Doug
On Jun 6, 2009, at 1:30 PM, Gareth Morgan wrote:
> 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
------------------------------------------------------------------------------
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