Hi,
As a long time Haskell fan, I've often wanted to write simple declarative code
but found this a little too verbose in Factor. e.g. Here is my price
calculations for a wedding reception:
: receptionPerHead ( -- price ) 60 ;
: receptionAttendants ( -- price ) 50 ;
: reception ( -- price ) receptionPerHead receptionAttendants * ;
: venueHire ( -- price ) 2800 ;
: total ( -- price ) [ venueHire , reception , ] { } make sum ;
Extrapolate this to about 5x the size and you have my actual wedding budget. I
think this contains too much programming stuff, making it hard to read compared
to the Haskell version:
receptionPerHead = 60
receptionAttendants = 50
reception = receptionPerHead * receptionAttendants
venueHire = 2800
total = sum [venueHire, reception]
So what I did was make:
SYNTAX: D:
CREATE-WORD
parse-definition
(( -- x ))
define-declared ;
so the factor code now looks like:
D: receptionPerHead 60 ;
D: receptionAttendants 50 ;
D: reception receptionPerHead receptionAttendants * ;
D: venueHire 2800 ;
D: total [ venueHire , reception , ] { } make sum ;
I like this better but the total still doesn't read quite nicely. I'd prefer
something like
{ venueHire reception } sum
... but that seems like I'd have to write special syntax to evaluate the words
in the literal.
My questions are:
Is what I'm doing idiomatic Factor?
Is there a better, completely different way of doing all of this (i.e. using
Factor like a spreadsheet)?
Is there a way of defining constants so they are substituted at parse-time?
Thankyou,
Luke
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk