morganstanley / hobbes

A language and an embedded JIT compiler

Home Page:http://hobbes.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Evaluation example gives different output

Chaz6 opened this issue · comments

When I run one of the evaluation examples, the output shown is different to that of the example.

The example is thus:-

> roll(|1=("chicken", roll(|1=("hot dog", roll(|1=("pizza", roll(|0=()|))|))|))|) :: ^x.(()+([char]*x))
"chicken":"hot dog":"pizza":[]
> cons("chicken", cons("hot dog", cons("pizza", nil())))
"chicken":"hot dog":"pizza":[]

The actual output is :-

> roll(|1=("chicken", roll(|1=("hot dog", roll(|1=("pizza", roll(|0=()|))|))|))|) :: ^x.(()+([char]*x))
"nekcihcgod tohazzip"
> cons("chicken", cons("hot dog", cons("pizza", nil())))
"nekcihcgod tohazzip"

I'm able to reproduce this on Nix too:

~ ∫ nix shell nixpkgs#hobbes -c hi -s -x -e 'roll(|1=("chicken", roll(|1=("hot dog", roll(|1=("pizza", roll(|0=()|))|))|))|) :: ^x.(()+([char]*x))'
"nekcihcgod tohazzip"

Thank you for reporting this, it looks like we have an issue printing the output, it's reversed. I'll fix it. The following works:

~ ∫ nix shell nixpkgs#hobbes -c hi                                                                                                                                                                                            [14:01:37] 
hi : an interactive shell for hobbes
      type ':h' for help on commands

> fix=\xs.reverse(slice(xs,0,size(xs)))
> fix(roll(|1=("chicken", roll(|1=("hot dog", roll(|1=("pizza", roll(|0=()|))|))|))|) :: ^x.(()+([char]*x)))
"pizzahot dogchicken"
>