How to run scheme in Julia? - julia

From the internet, I saw a discussion that run
julia --lisp
would start femtolisp.
I tried, the femtolisp quit as soon as it start:
PS C:\Users\Nick> julia --lisp
; _
; |_ _ _ |_ _ | . _ _
; | (-||||_(_)|__|_)|_)
;-------------------|----------------------------------------------------------
>
PS C:\Users\Nick>
I'm running Julia 0.3.8 on Windows 7. Anyone know what's wrong with this?
Update
I post a new issue here
https://github.com/JuliaLang/julia/issues/11481
(Thanks, #IainDunning.)

Related

Assembly.LoadFrom fails but only sporadically

I want to write a program that watches a .dll for changes. When a change happens, it should load the assembly and invoke the foo function inside.
I have some code that should implement this, but it behaves strangely. Sometimes it works. Sometimes the assembly it loads will be an old version. Sometimes it will throw a BadImageFormatException exception.
Here is my program code (it is F# but I think this is a general .NET Core question):
module HotReloadDemo
open System
open System.IO
open System.Reflection
[<EntryPoint>]
let main argv =
let assemblyPath = argv.[0] // Path to the .dll to watch
let mutable lastWriteTime = DateTime.MinValue
while true do
let writeTime =
if File.Exists assemblyPath
then
File.GetLastWriteTimeUtc assemblyPath
else
lastWriteTime
if writeTime > lastWriteTime
then
lastWriteTime <- writeTime
try
printfn "Last write time: %O " lastWriteTime
printfn "Waiting for the build to finish (this is a hack)... "
Threading.Thread.Sleep 10000 // 10s is plenty long enough for the build to finish
printfn "Loading assembly path from: %s " assemblyPath
let assembly = Assembly.LoadFrom assemblyPath
printfn "Got assembly: %O" (assembly.GetName ())
let foo : (Unit -> int) option =
assembly.GetExportedTypes()
|> Array.tryHead
|> Option.bind (fun t -> t.GetMethod "foo" |> Option.ofObj)
|> Option.map (fun m -> (fun () -> m.Invoke (null, Array.empty) :?> int))
match foo with
| Some foo ->
printfn "foo () = %O" (foo ())
| None ->
printfn "foo not found"
with exn ->
printfn "%O" exn
else
()
Threading.Thread.Sleep 1000
0
I then have a very simple library to be watched in another project like this:
module HotReload
let foo () =
123456
To test it, I launch the "watcher" program. It successfully loads and invokes foo.
Then, I modify my library (e.g. to return a different number) and build it with dotnet build.
The watcher detects the change, loads the assembly again and invokes foo, but it prints the number from before the change!
Then, I modify the library again with a different number. It detects the change but crashes:
...
Loading assembly path from: ../hot-reload-lib/bin/Debug/netstandard2.0/hot-reload-lib.dll
System.BadImageFormatException: Could not load file or assembly '<Unknown>'. Index not found. (0x80131124)
File name: '<Unknown>'
at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
...
What is going on here?
dotnet --version
3.0.100
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.3 LTS
Release: 18.04
Codename: bionic

Julia: unintended extension of base functions

I have the following, incomplete Julia code:
mutable struct Env
end
function step(env, action:UInt32)
return ones(8), 1.0, true, Dict()
end
function reset(env)
return ones(8)
end
When I try to use it, I get the following errors:
LoadError: error in method definition: function Base.step must be
explicitly imported to be extended
LoadError: error in method definition: function Base.reset must be
explicitly imported to be extended
I don't know what Base.step and Base.reset are, and I don't want to extend them.
Is there some way for me to keep these function names without extending the base functions? If I do just extend the base functions with my completely unrelated methods, are there going to be problems?
I really do not want to change the names of my functions because I want to keep them in line with the OpenAI Gym API.
Define them inside a module like this
module Gym
mutable struct Env
end
function step(env, action::UInt32)
return ones(8), 1.0, true, Dict()
end
function reset(env)
return ones(8)
end
end
Then you can call them directly as step and reset inside the module. Outside the module you have to qualify them like this: Gym.step and Gym.reset.
Additionally - note that you get this problem only after you introduce step and reset in Main module before trying to extend them (e.g. by calling or referencing them). So when starting a clean Julia session this will work:
$ julia
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.0.2 (2018-11-08)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> step(x) = x
step (generic function with 1 method)
but this will fail:
$ julia
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.0.2 (2018-11-08)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> step
step (generic function with 4 methods)
julia> step(x) = x
ERROR: error in method definition: function Base.step must be explicitly imported to be extended

How do you access the conv function in Julia 1.0.0

This question on stackoverflow uses Julia 0.6.1, as shown here:
The convolution function in Julia has the following behaviour:
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: https://docs.julialang.org
_ _ _| |_ __ _ | Type "?help" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.6.1 (2017-10-24 22:15 UTC)
_/ |\__'_|_|_|\__'_| | Official http://julialang.org/ release
|__/ | x86_64-pc-linux-gnu
julia> conv([1,2,NaN],[1])
3-element Array{Float64,1}:
NaN
NaN
NaN
The same thing in Julia 1.0.0 produces the following Error output:
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.0.0 (2018-08-08)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> conv([1,2,NaN],[1])
ERROR: UndefVarError: conv not defined
Stacktrace:
[1] top-level scope at none:0
How does one access the conv function in Julia 1.0.0?
The convolution function has been moved to the package DSP.jl which stands for Digital Signal Processing.
It is generally recommended to use Julia v0.7 when trying to port pre v0.7 code to Julia v1.0. In fact, this is the only reason v0.7 exists.
When calling conv in v0.7 you get all the information you need:
julia> conv(rand(10))
ERROR: conv has been moved to the package DSP.jl.
Run `Pkg.add("DSP")` to install it, restart Julia,
and then run `using DSP` to load it.
In case you'd want to avoid running v0.7 on you machine just to find out where something has been moved to, you can also search for the old function's name in deprecated.jl. Searching for conv we find:
for f in [:conv, :conv2, :deconv, :filt, :filt!, :xcorr]
#eval Base.#deprecate_moved $f "DSP"
end
Although source code, I believe #deprecate_moved "DSP" is understandable.

WebStorm: New AngularCli Project: Error: directory should match format "path"

When I try to create a new Angular Cli project:
receive this message (in Run window) after a few seconds after executing ng new angularcli --dir=. command by IDE:
"C:\Program Files\nodejs\node.exe" C:\Users\I\AppData\Roaming\npm\node_modules\#angular\cli\bin\ng new angularcli --dir=.
Error: Schematic input does not validate against the Schema: {"directory":".","name":"angularcli","skipGit":false,"style":"css","version":"1.7.3","commit":{"message":"chore: initial commit from #angular/cli\n\n _ _ ____ _ ___\n / \\ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|\n / △ \\ | '_ \\ / _\\` | | | | |/ _\\` | '__| | | | | | |\n / ___ \\| | | | (_| | |_| | | (_| | | | |___| |___ | |\n/_/ \\_\\_| |_|\\__, |\\__,_|_|\\__,_|_| \\____|_____|___|\n |___/\n","name":"Angular CLI","email":"angular-cli#angular.io"},"path":"app","sourceDir":"src","inlineStyle":false,"inlineTemplate":false,"routing":false,"prefix":"app","skipTests":false,"skipInstall":false,"linkCli":false,"minimal":false,"serviceWorker":false}
Errors:
.directory should match format "path"
Schematic input does not validate against the Schema: {"directory":".","name":"angularcli","skipGit":false,"style":"css","version":"1.7.3","commit":{"message":"chore: initial commit from #angular/cli\n\n _ _ ____ _ ___\n / \\ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|\n / △ \\ | '_ \\ / _\\` | | | | |/ _\\` | '__| | | | | | |\n / ___ \\| | | | (_| | |_| | | (_| | | | |___| |___ | |\n/_/ \\_\\_| |_|\\__, |\\__,_|_|\\__,_|_| \\____|_____|___|\n |___/\n","name":"Angular CLI","email":"angular-cli#angular.io"},"path":"app","sourceDir":"src","inlineStyle":false,"inlineTemplate":false,"routing":false,"prefix":"app","skipTests":false,"skipInstall":false,"linkCli":false,"minimal":false,"serviceWorker":false}
Errors:
.directory should match format "path"
Done
Similarly on Mac:
It seems to be relevant to this part of the command: --dir=.. But I don't know why and how to correct it!
(I know that I can create a new project via command line independently and then open it in WebStorm, but don't want this for some reasons.)
it's a known cli 1.7.x issue - https://github.com/angular/angular-cli/issues/9655; unfortunately we have been unable to fix it on our end so far... We are working with Angular team on this, please follow WEB-31291 for updates.
As a workaround, you can try creating new angular app in terminal using ng new <project_name> and then opening the generated project folder in WebStorm
Do not include project name special characters. for example this is wrong: www_testProject.
This is correct: wwwTestProject
I have this issue, But I got a solution which is works for me is:
New project names must start with a letter, and must contain only alphanumeric characters or dashes. When adding a dash the segment after the dash must also start with a letter.
Invalid- new_something
Valid- new-something
According to my last test, there is no problem. I upgraded my tools (Angular CLI v7.1.4 and WebStorm v2018.3.2):

Speeding up `using Distributions` in Julia

On my machine, with the development version of Julia, the command import Distributions takes 6.6 seconds. Is there a way to make this faster? Is static precompilation going to be part of Julia 0.4?
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: http://docs.julialang.org
_ _ _| |_ __ _ | Type "help()" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.4.0-dev+4603 (2015-05-02 18:25 UTC)
_/ |\__'_|_|_|\__'_| | Commit 803193e* (17 days old master)
|__/ | x86_64-unknown-linux-gnu
julia> tic(); import Distributions; toc()
elapsed time: 6.62282982 seconds
6.62282982
Static precompilation might happen for Julia 0.4, not 100% clear yet if it'll make it in.
If you'd like to do it somewhat manually by baking it into your "system image", check out the handy package SystemImageBuilder.jl.

Resources