tag:blogger.com,1999:blog-8513438391157777465.post3323031387067942682..comments2023-04-07T05:56:45.278-07:00Comments on Re: Factor: Uniquemrjbq7http://www.blogger.com/profile/06842721076008035602noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-8513438391157777465.post-48098612570838244302011-08-21T10:09:24.715-07:002011-08-21T10:09:24.715-07:00Nice article!
I'd say the longer version is a...Nice article!<br /><br />I'd say the longer version is actually closer to the Racket example, which is written in a surprinsingly imperative style (not to scare the newcomers, I guess..). When you write the above in a more functional Racket, both solutions look quite similar (ummm... backwards, of course):<br /><br /><br />(define (unique-lines)<br /> (for-each displayln (remove-duplicates (port->lines))))<br /><br />(define (unique-file f)<br /> (with-input-from-file f unique-lines))<br /><br />I'd say this is one more example of how related the concatenative and functional paradigms are...<br /><br />Cheers!<br /><br />Joan.<br />PS: Instead of with-input-from-file, you can just pass a parameter to port->lines, or use file->lines in the first place, but this is closer to the Factor version...CertainlyNotWestonhttps://www.blogger.com/profile/10135207239219096432noreply@blogger.comtag:blogger.com,1999:blog-8513438391157777465.post-62989965491422431932011-08-21T04:57:14.173-07:002011-08-21T04:57:14.173-07:00I prefer the version with less stack gymnastic whe...I prefer the version with less stack gymnastic when you currify the hash set:<br /><br />HS{ } clone [ <br /> 2dup in? [ 2drop ] [<br /> [ adjoin ]<br /> [ drop print flush ] 2bi<br /> ] if<br />] curry each-line<br /><br />Cheers,<br />JonJonhttps://www.blogger.com/profile/15764551863353269999noreply@blogger.com