ssadler / hawk

Awk for Hoodlums
BSD 3-Clause "New" or "Revised" License
35 stars 2 forks source link

Merge Renderable and Rows #17

Open melrief opened 11 years ago

melrief commented 11 years ago

Renderable is the hsl class for types that can be shown as output. Rows is the hsp class for types that can be shown as output. This two classes are the same thing. I propose to merge the two files by unify the two concepts behind. I'm the author of Rows, so I would like to expose the idea behind it and I would like to understand how it differs from Renderable.

In hsp there were three different level of representation for a type a:

> printRows False (repr 1)
1
> printRows False (repr (1,2))
1
2
> printRows False (repr [1,2,3])
1
2
3
> printRows False (repr "Test")
test
> printRows False (repr (Just 1))
1
> printRow False (repr' 1)
1
> printRow False (repr' (1,2))
1 2
> printRow False (repr' [1,2,3])
1 2 3
> printRow False (repr' "test")
test
> printRow False (repr' (Just 1))
1
> 

I follow this rule

(printRow needs a boolean as first value that tells it if it must stop at the first error or ignore it and continue)

One major improvement could be to let the user fallback to show for debugging purpose (to see what is happening). I think this is very important, in particular if we want to keep this king of representation of Maybe. I'm a great supporter of this.

melrief commented 11 years ago

One note: I don't want necessary to separate rows usigng newline and Row values using space. That should be the standard way but I'd like to let the user configure it. I don't know how to do that, but I think it is possible, for the sake of customizability of hawk.

gelisam commented 11 years ago

@ssadler's Renderable is displaying Maybe 1 as Maybe 1, while my experimental branch is displaying "1", like yours. In addition to Rows (which I call RenderableFile) and Row (which I call RenderableLine), I have RenderableItem, which deals with the above special case for Maybe and also for the special case for string.

Both Renderable and RenderableItem treat strings specially, by writing the raw string instead of the quoted string. I see hsp does that too, even though that's not what I would have inferred from

Show a: a is a single value inside a collection c that instantiate Row.

The only other difference I notice between the two systems is that both versions of hsl always render tuples as a tab-separated line, while you sometimes interpret them as multiple lines. Also, we use tabs, not spaces.

melrief commented 11 years ago

I understand @ssadler 's point of view about Maybe, it can be misleading to render it as the value that it contains. But the show output of containers like Maybe and Either is far from be usable in a terminal, in particular considering the spaces. I think we should promote the usability of hawk inside the shell by hiding containers details, like hsp and @gelisam 's branch of hsl do, but also give an option -r to the user that shows the "real form" of the output.

> hawk -e "Just 1"
1
> hawk -r -e "Just 1"
Just 1

By the way, the user can always fallback to show to get the common representation of that value:

> hawk -e "Just 1"
1
> hawk -e "show (Just 1)"
Just 1
ssadler commented 11 years ago

BTW I don't want to render Maybe a as "Maybe a", so don't worry about that :).

On 8 August 2013 14:31, Mario Pastorelli notifications@github.com wrote:

I understand @ssadler https://github.com/ssadler 's point of view about Maybe, it can be misleading to render it as the value that it contains. But the show output of containers like Maybe and Either is far from be usable in a terminal, in particular considering the spaces. I think we should promote the usability of hawk inside the shell by hiding containers details, like hsp and @gelisam https://github.com/gelisam 's branch of hsl do, but also give an option -r to the user that shows the "real form" of the output.

hawk -e "Just 1" 1 hawk -r -e "Just 1" Just 1

By the way, the user can always fallback to show to get the common representation of that value:

hawk -e "Just 1" 1 hawk -e "show (Just 1)" Just 1

— Reply to this email directly or view it on GitHubhttps://github.com/ssadler/hawk/issues/17#issuecomment-22323454 .

ssadler commented 11 years ago

I'm up for:

Either types should print Right to stdout and Left to stderr.

If the user wants to use 'show' then he should do that, no need for a command line option.

On 8 August 2013 16:05, Scott Sadler ssadler@mashi.org wrote:

BTW I don't want to render Maybe a as "Maybe a", so don't worry about that :).

On 8 August 2013 14:31, Mario Pastorelli notifications@github.com wrote:

I understand @ssadler https://github.com/ssadler 's point of view about Maybe, it can be misleading to render it as the value that it contains. But the show output of containers like Maybe and Either is far from be usable in a terminal, in particular considering the spaces. I think we should promote the usability of hawk inside the shell by hiding containers details, like hsp and @gelisam https://github.com/gelisam's branch of hsl do, but also give an option -r to the user that shows the "real form" of the output.

hawk -e "Just 1" 1 hawk -r -e "Just 1" Just 1

By the way, the user can always fallback to show to get the common representation of that value:

hawk -e "Just 1" 1 hawk -e "show (Just 1)" Just 1

— Reply to this email directly or view it on GitHubhttps://github.com/ssadler/hawk/issues/17#issuecomment-22323454 .

ssadler commented 11 years ago

(printRow needs a boolean as first value that tells it if it must stop at the first error or ignore it and continue)

What recoverable error can it encounter?

melrief commented 11 years ago

For example head [] throws an exception and if the exception is not caught then the program is killed. Error are then printed on stderr but the execution continues.

gelisam commented 11 years ago

As a bash scripter who always uses "set -e", I would find that really annoying. If anything fails, I want my script to stop promptly and as noisily as possible! By printing an error message to stderr, and especially by exiting with a non-zero error code.

melrief commented 11 years ago

I admit that it was an experiment to follow awk rules. In practices, when you write 'awk '{print $i}'' with i > number of words, it prints empty line. I didn't have the possibility to test this.

gelisam commented 11 years ago

I didn't have the possibility to test this.

Because you don't have awk on your machine? I do, and I confirm awk's behaviour:

> seq 3 | tr '\n' ' ' | awk '{print $4}'

> seq 5 | tr '\n' ' ' | awk '{print $4}'
4
melrief commented 11 years ago

No I meant I didn't test hsp with this behaviour, ignoring user errors. I prefer to correct errors when I see them instead of ignoring them.

For now hawk has exactly the awk behaviour:

> seq 3 | tr '\n' ' ' | hsp -m '(L.!! 3) . words'
Prelude.(!!): index too large

> seq 5 | tr '\n' ' ' | hsp -m '(L.!! 3) . words'
4

The error on the first expression is printed to stderr and the empty line is printed to stdout. So it is coherent with awk (that is not necessarily what we want).