isaacg1 / pyth

Pyth, an extremely concise language. Try it here:
https://pyth.herokuapp.com/
MIT License
263 stars 57 forks source link

Added REPL mode #200

Closed Maltysen closed 8 years ago

Maltysen commented 8 years ago

I found myself using Pyth for a lot of daily "desktop calculator" tasks, so I wrote a little REPL for it. This is called up when one has no cmd args, or uses the -r or --repl flags.

It just runs each line as a program, but sends the output of one into the other allowing things like:

>>> 6
6
>>> y
12
>>> 
24
>>> +3
27
>>> U
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]

(Note that an empty line repeats the previous command).

It also uses the cmd module for up-arrow/down-arrow history functionality.

I also included help functionality that lookups the command you enter in the docs:

>>> help h
h  <num>                  A + 1.
>>> ? m
m  <l:d> <col/num>        Map A(_) over B. d -> k -> b ->

(help and ? are the same).

I made up the intro txt, flag name, etc. you probably want to change them, and there probably are some bugs.

FliiFe commented 8 years ago

This can only be aproved, there is no possible regression merging this (AFAIK).

Just a curiosity, why would you use pyth for daily calculation tasks while other languages (e.g python) have much more natural syntax ( 5+4, instead of +5 4) ?

jakobkogler commented 8 years ago

Probably because Pyth has more prebuild functions. It's easy to count the number of occurences, make a run-lenth-encoding, convert a list of numbers to a base, ... I often wished some of them are standard in Python. Although a simpler solution would be to open the Python REPL and import all methods from the file macros.py.

2016-06-23 16:30 GMT+02:00 Théophile Cailliau notifications@github.com:

This can only be aproved, there is no possible regression merging this (AFAIK).

Just a curiosity, why would you use pyth for daily calculation tasks while other languages (e.g python) have much more natural syntax ( 5+4, instead of +5 4) ?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/isaacg1/pyth/pull/200#issuecomment-228068237, or mute the thread https://github.com/notifications/unsubscribe/AG0AlaevOZtoI5jv7uCt8eOFkqzk9YN_ks5qOpiGgaJpZM4I8Z95 .

Maltysen commented 8 years ago

@FliiFe pyth is a lot more powerful and flexible than other languages, for example, j vs python join. I also don't have to import anything, all the built-ins just "work" (e.g. with the itertools_norm) and everything being one character makes writing quick things very fast.

This obviously comes at the cost of maintainability, etc. but I find it really nice for small tasks.

Maltysen commented 8 years ago

Dammit, mobile I closed that by mistake when I hit "close and comment"

isaacg1 commented 8 years ago

This is an impressively simple implementation of the repl.