read-eval-print-loop

Swift date(byAdding:to:) returns nil for trivial calculation in REPL

南楼画角 提交于 2020-04-07 06:52:21
问题 I expect this to return a Date object representing the time one hour from now: Calendar.current.date(byAdding: DateComponents(hour: 1), to: Date()) However it returns nil . This seems like a rather straightforward use of the API so perhaps I have some fundamental misconception about how this API should work? This only appears to affect the swift command line REPL included with Xcode (version 11.3.1 on macOS Catalina 10.15.3). Interestingly, wrapping the above code in a print() call forces it

let and var Invalid redeclaration of const in Swift REPL

本秂侑毒 提交于 2020-01-24 12:32:53
问题 In Swift REPL I can assign a constant with let , but why can I modify it later using var ? let name = "al" var name = "bob" Swift is not complaining here, but wasn't name a constant? 回答1: Redeclaring a variable (in the same scope) is not valid in Swift: $ cat test.swift let name = "al" var name = "bob" $ swiftc test.swift test.swift:2:5: error: invalid redeclaration of 'name' var name = "bob" ^ test.swift:1:5: note: 'name' previously declared here let name = "al" ^ However, the Swift REPL

Customized display of composite types in Julia

隐身守侯 提交于 2020-01-22 12:16:31
问题 Suppose you define a new composite type in Julia and a variable of that type: type MyType α::Int64 β::Vector{Float64} γ::Float64 MyType(α::Int64, β::Vector{Float64}, γ::Float64) = new(α, β, γ) end mt = MyType(5, [1.2, 4.1, 2], 0.2) Now if you are in REPL mode, you can simply check the value of mt by typing mt and pressing Enter: mt MyType(5,[1.2,4.1,2.0],0.2) If I want to customize the way variables of MyType are displayed, I can define a function and use it like customized_display(mt) :

Scala REPL fails to autocomplete methods that comes from implicit conversion

半腔热情 提交于 2020-01-16 01:14:10
问题 if I write in scala 2.10 REPL (interactive Scala shell): """\w""". And press TAB it gives me: + asInstanceOf charAt codePointAt codePointBefore codePointCount compareTo compareToIgnoreCase concat contains .... However, .r is missing. When I put the same string into eclipse, it offers me .r as well. The same is true if I insert import scala.util.matching._ before. Why REPL is not offering all possibilities? Even bigger problem REPL has if i try to work with unicode, e.g. I write: """\p{L}""".

How to get Python interactive console in current namespace?

六月ゝ 毕业季﹏ 提交于 2020-01-11 16:02:08
问题 I would like to have my Python code start a Python interactive console (REPL) in the middle of running code using something like code.interact(). But the console that code.interact() starts doesn't see the variables in the current namespace. How do I do something like: mystring="hello" code.interact() ... and then in the interactive console that starts, I should be able to type mystring and get "hello". Is this possible? Do I need to set the "local" argument of code.interact() to something?

Why do I lose all symbols when using in-ns to move to a new namespace?

浪尽此生 提交于 2020-01-11 10:47:09
问题 Running the following code in a Leiningen REPL: (in-ns 'my-namespace.core) (+ 2 2) results in this error: CompilerException java.lang.RuntimeException: Unable to resolve symbol: + in this context Why? 回答1: When you create a new namespace using in-ns , the core namespace ( clojure.core ) is not referred by default. "Referring" a namespace means including it in your namespace in such a way that you can refer to that namespace's symbols as your own. It is still possible to use symbols from

How to resolve promises when using app with REPL

拥有回忆 提交于 2020-01-11 05:08:08
问题 I've got a basic Node webserver (Koa.js + a ORM). I like to start it with a REPL meaning I can use my app like a CLI-tool. All my queries return Promises but I don't know how I can resolve them in the REPL. How can I resolve them? For example the following code (fetch() queries the database and returns a promise) gives only this output Promise {_bitField: 4325376, _fulfillmentHandler0: undefined, _rejectionHandler0: undefined …} Transaction.where('reference', '1').fetch().then((res) => return

Can I clean the repl?

走远了吗. 提交于 2020-01-10 06:52:18
问题 I have played with a lot of code in a repl console, how can I clear it? I would like a fresh one without restarting it. Can that be done? 回答1: If you want to clear the current namespace of all temporary variables and functions you declared you can use this one liner (or make a function of it) : (map #(ns-unmap *ns* %) (keys (ns-interns *ns*))) or (ns myutil) (defn ns-clean "Remove all internal mappings from a given name space or the current one if no parameter given." ([] (ns-clean *ns*)) (