Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added REPL mode #200

Merged
merged 3 commits into from
Jun 23, 2016
Merged

Added REPL mode #200

merged 3 commits into from
Jun 23, 2016

Conversation

Maltysen
Copy link
Contributor

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
Copy link
Contributor

FliiFe commented Jun 23, 2016

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
Copy link
Contributor

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
#200 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AG0AlaevOZtoI5jv7uCt8eOFkqzk9YN_ks5qOpiGgaJpZM4I8Z95
.

@Maltysen
Copy link
Contributor Author

@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 Maltysen closed this Jun 23, 2016
@Maltysen Maltysen reopened this Jun 23, 2016
@Maltysen
Copy link
Contributor Author

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

@isaacg1
Copy link
Owner

isaacg1 commented Jun 23, 2016

This is an impressively simple implementation of the repl.

@isaacg1 isaacg1 merged commit 66bbfd6 into isaacg1:master Jun 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants