interpreter

Interpreter-style output in Python 3 (maybe about sys.displayhook?)

两盒软妹~` 提交于 2019-12-11 06:28:17
问题 I'm making a little toy command window with Tk, and currently trying to make it copy some interpreter behavior. I'd never scrutinized the interpreter before, but it's decisions on when to print a value are a little mystifying. >>> 3 + 4 # implied print(...) 7 >>> 3 # implied print(...) 3 >>> a = 3 # no output, no implied print(...), bc result is None maybe? >>> None # no output, no print(...) implied... doesn't like None? >>> print(None) # but it doesn't just ban all Nones, allows explicit

Initialize interpreter with variables

房东的猫 提交于 2019-12-11 03:48:58
问题 How do I initialize the python interpreter such that it already has variables in its memory? For example, how could I initialize a[n i]Python interpreter, and type as my first input: In [1]: today Out[1]: '2015-05-05 17:49:32.726496' without first binding the name str(today = datetime.datetime.today()) ? 回答1: If you are using ipython, you can configure it to load scripts automatically for you. Run $ ipython profile create which will create default profile in your home directory. Create a file

Is it possible to define new ADTs in GHCi

若如初见. 提交于 2019-12-11 03:36:03
问题 While commenting on new features in ghci I wished that ghci had the ability to declare type declaration and declaring new ADT types, someone informed that it was indeed possible, and after searching I found this page which told me I could do let numUniques' :: (Eq a) => [a] -> Int; numUniques' = length . nub Apparently that same sort of syntax works for pattern matching (ex. let a 1=True;a 2=False). Creating ADTs would make it almost perfect? Does anyone know if it is currently possible?

Interpret text input as PHP

陌路散爱 提交于 2019-12-11 02:27:08
问题 I want to let users test out a PHP class of mine, that among other things crops and resizes images. I want them to write PHP code in a text field, send the form, and then their code will be run. How can I do this? Or is it other safe ways to let users (anyone) demo a PHP class? 回答1: Yes. You can use the eval statement in php (linked earlier by John http://us2.php.net/manual/en/function.eval.php), however be very careful. You really don't want users to be able to run code on your machine

Why does typing _ in the Python interpreter return True? [duplicate]

女生的网名这么多〃 提交于 2019-12-11 02:22:20
问题 This question already has answers here : Get last result in interactive Python shell (3 answers) Closed 5 years ago . I am getting very weird interpreter behaviour: >>> _ True >>> type(True) <class 'bool'> >>> type(_) <class 'bool'> I tried this because _ came up as a suggestion in Bpython, but it seems to work in the normal interpreter too. I am using Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 16 2013, 23:39:35) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Can anybody explain why _ is a

Writing an interpreter in OCaml [closed]

隐身守侯 提交于 2019-12-10 20:22:03
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I'm following a course in my University that ask me to write an interpreter in OCaml of a language starting from its operational semantics. Unfortunately, they didn't give us much resources from which we can learn about it, except from the lesson's slides. Can someone suggest me some book or some website where I

While True or while 1? [duplicate]

て烟熏妆下的殇ゞ 提交于 2019-12-10 19:37:25
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: while (1) Vs. for while(True) — Why is there a difference? I see sometimes in other people code "while 1" instead of "while True". I think using True is more pythonic, but I wanted to check if there is any difference in practice. So I tried to do the following, and the result is surprising. For what I can see it looks like the interpreter can optimize away the 1 boolean conversion while it doesn't with the True,

Perl interpreter for PHP

霸气de小男生 提交于 2019-12-10 19:00:28
问题 Some of the functions I am planning for a new site of mine are already available as free Perl modules. Hence I am looking at the possibility of using them, rather than coding them again in PHP. I was planning to use exec or system function to call the perl script, which will be slow. But I came across a pecl extension which allows PHP to interpret perl code. Will this affect the performance of my other php pages, which are not using the perl script? I understand that the extra module will

Writing an interpreter with OCaml GADTs

梦想的初衷 提交于 2019-12-10 17:37:00
问题 I am writing a small interpreter in OCaml and am using GADTs to type my expressions: type _ value = | Bool : bool -> bool value | Int : int -> int value | Symbol : string -> string value | Nil : unit value | Pair : 'a value * 'b value -> ('a * 'b) value and _ exp = | Literal : 'a value -> 'a exp | Var : name -> 'a exp | If : bool exp * 'a exp * 'a exp -> 'a exp and name = string exception NotFound of string type 'a env = (name * 'a) list let bind (n, v, e) = (n, v)::e let rec lookup =

What does it mean to say that the source code is always available to interpreters?

拥有回忆 提交于 2019-12-10 17:07:44
问题 From Thinking in C++ - Vol. 1 : Interpreters have many advantages. The transition from writing code to executing code is almost immediate, and the source code is always available so the interpreter can be much more specific when an error occurs. What does the bold line mean? Does it mean that the interpreter cannot work unless whole of the program is in memory? Which means we cannot divide the program into modules and then have the modules interpreted as and when needed (like we do with