Arc Forumnew | comments | leaders | submitlogin
2 points by thaddeus 5463 days ago | link | parent

I only spent about 5 min looking at factor. There are many appealing features, but I went as far as seeing "Hello World" and moved on.

Hello World in Arc:

   arc> (pr "Hello World")
   Hello World
Hello World in Haskell:

   Prelude> putStrLn "Hello World"
   Hello World
Hello World in Factor:

   USE: io
   IN: hello-world
   hello ( -- ) "Hello world" print ;
   MAIN: hello
The code syntax is just not pleasant on the eye.


1 point by fallintothis 5463 days ago | link

Actually, you've presented Factor's hello world as though it were a file. They have a REPL, too -- they call it the listener, though. You can either use the GUI version it comes with or from the command line do

  $ factor -run=listener
  Loading ~/.factor-rc
  ( scratchpad ) "Hello word" print
  Hello word
The syntax is aesthetically pleasing in an important way: it's very consistent. While postfix might not look "right" at first, it belies an incredibly simple parsing algorithm -- one that allows for easy definitions of the words like USE: and IN: and even :.

Not that you need to learn Factor. Just sayin'.

-----

1 point by thaddeus 5463 days ago | link

Actually it's not I that present it this way:

http://concatenative.org/wiki/view/Factor/Examples

I presumed that without "USE: io" that "Hello World" was not being sent to the standard output where as my arc/haskell examples actually were. i.e. With arc I could load/run a file/script with (pr "Hello World") and it would output "Hello World", but with Factor?...

I just went to each language site and looked for the Hello World examples. It may be that Factor could do a better job advertising AND that I need to spend more than 5 minutes looking :)

Another language to add to my list to learn....

-----

2 points by fallintothis 5462 days ago | link

Yikes, editing race-conditions. I'll fork this off into a different reply.

I presumed that without "USE: io" that "Hello World" was not being sent to the standard output

Actually, that line's like an import statement in Haskell. I would say it's like load in Arc, but that's not really true; USE: and import have to do with module systems, which Arc doesn't have. If you're already familiar with modules, you can skip this stupid explanation, but...

Basically, modules let you structure your functions into different places so that they don't mess with each other. As a silly example, maybe you write a text adventure in Arc and name a function get, as in (get 'ye-flask). But Arc already defines a function called get, as in (map (get 'a) list-of-hash-tables). You want to be able to use both of them at the same time, but would rather not rename your new function. If Arc had modules, you could qualify the function name with the name of the module in which it's defined. Something like

  (use 'game)
  (game.get 'ye-flask)
  (map (get 'a) list-of-hash-tables)
But when you don't want to use Arc's get, you could still overwrite it with the text adventure's get and not need to prefix it with the module name.

This is a vast oversimplification, of course, but that's essentially what they do. So, in languages like Factor, all the I/O routines are in a module called "io". In the io library is a function called print. If you don't need to print things, you don't need to USE: io, which helps keep the "surface area" of your code small.

i.e. With arc I could load/run a file/script with (pr "Hello World") and it would output "Hello World", but with Factor?...

Because Arc doesn't separate anything into modules, you don't need to import things like pr since it's already there by default. The reason the Haskell code in my other reply could do without the import is that putStrLn is similarly defined in Haskell by default: it's in the so-called "standard prelude". That's what the Prelude> prompt tells you in GHCi. You can import other libraries in GHCi, and the prompt will tell you what you're using:

  Prelude> :m + Control.Monad
  Prelude Control.Monad> :m + System.IO
  Prelude Control.Monad System.IO> :m + Foreign.C.Types
  Prelude Control.Monad System.IO Foreign.C.Types>
Hope that helps.

-----

1 point by thaddeus 5462 days ago | link

> Yikes, editing race-conditions. I'll fork this off into a different reply.

yup... I should really write then post :)

> Hope that helps.

It really does. Thanks for taking the time to reply.

-----

1 point by fallintothis 5463 days ago | link

It may be that Factor could do a better job advertising

True. After all, transliterating the Factor example to Haskell looks something like

  module Main where
  import System.IO (putStrLn)

  hello :: IO ()
  hello = putStrLn "Hello world"

  main = hello
Of course, in Haskell you would just write

  module Main where

  main = putStrLn "Hello world"
My point here is that the Factor code doesn't do any real magic. When you give it a chance, the syntax is quite powerful.

It's really neither here nor there: picking a language and getting at least somewhat comfortable with it is going to be better than endlessly deliberating. They all have their merits (even bad languages!).

I'm babbling. Move along. :)

-----