Pharo Metalink not works on #ifTrue: send node - pharo

When I add MetaLink to all send nodes in the following code, the Metalink on #ifTrue: not works:
aMethod
10 = 11
ifTrue: [ ^ 3 ]
code to add MetaLinks:
ast sendNodes do: [ :n |
n link: (MetaLink new
metaObject: [ :node |
Transcript show: node asString; cr ];
arguments: #(node);
selector: #value:;
control: #before;
yourself) ]
Can anyone explain why this happens?
How can I add a MetaLink on a #ifTrue: send?

Thanks to the comment from # LeandroCaniglia, this is because of compile optimization.
You can uncheck Inline If in Opal Compiler settings and recompile the method.
After recompile, reinstall your Metalinks and you will see #ifTrue: as a message call.

Related

.exe has stopped working when use thread module

I just copy the code from the example on nim's offical documentation:
import std/locks
var
thr: array[0..4, Thread[tuple[a,b: int]]]
L: Lock
proc threadFunc(interval: tuple[a,b: int]) {.thread.} =
for i in interval.a..interval.b:
acquire(L) # lock stdout
echo i
release(L)
initLock(L)
for i in 0..high(thr):
createThread(thr[i], threadFunc, (i*10, i*10+5))
joinThreads(thr)
deinitLock(L)
$ nimble build --threads:on
Verifying dependencies for thread#0.1.0
Building thread/thread.exe using c backend
$ .\thread
then thread.exe crashed...
thread.exe
0.0.0.0
630c5e83
libwinpthread-1.dll
6.3.9600.20512
62cdfc6e
c0000135
00000000000ed1b0
1fc8
01d8bb71e28918ba
F:\MyProjects\Nim\thread\thread.exe
libwinpthread-1.dll
2044d161-2765-11ed-827a-6c86063c07b4
I have no ideas about it...Can anybody help me? Thanks a lot.
Gave it a try in Windows 8.1, it does fail.
Apparently is a recent regression in nim you can make it work if you compile it with --threads:on --tlsEmulation:on (or make sure mingw binaries is on your PATH).

What's the normal procedure for finding the name of the necessary ESLint package based on the config name given in the error message?

I was just struggling with the error below in my IDE for a frustratingly-long time:
ESLint: Error: Failed to load config "#vue/typescript" to extend from.
After a lot of Googling and running commands I found online, I eventually found that what (seemed to) fix the problem was running this:
yarn add -D #vue/eslint-config-typescript
My question is: How was I supposed to figure that out? Is there some website or service or something where I could have searched for #vue/typescript and found out that the package I needed to install was #vue/eslint-config-typescript?
Ok, I figured it out: in the ESLint docs, it says that basically that the part after the forward-slash should be understood to always start with eslint-plugin:
They show the following examples:
"plugins": [
"jquery", // means eslint-plugin-jquery
"#jquery/jquery", // means #jquery/eslint-plugin-jquery
"#foobar" // means #foobar/eslint-plugin
]

Why can't clang find napi.h header - node-addon-api

This is my first time writing a nodejs addon and been trying to make node-addon-api package work for hours but I dont get clang to find the napi header file thus i dont get
autocompletion in vim and compiler throws a fatal error about it. I've followed node-addon-examples repo but nothing works.
In vim, when including the header file i get this message:
✘ 3 #include <napi.h>
4 'napi.h' file not found
5 int main(in [clang: pp_file_not_found]
And compiler throws:
cc1: warning: /usr/include/node/node_api.h: not a directory
/home/prxvvy/workspace/a/source/main.c:3:10: fatal error: napi.h: No such file or directory
3 | #include <napi.h>
| ^~~~~~~~
However if I include the node_api header directly like this it does work because, as far as I know when installed nodejs the header files were installed in /usr/include/node but I feel like its not the best way to do the job.
3 #include <node/node_api.h>
4
My binding.gyp file is:
1 {
2 "targets": [
3 {
4 "target_name": "lib",
5 "cflags!": ["-fno-exceptions"],
6 "cflags_cc!": ["-fno-exceptions"],
7 "cflags": ["-Wall", "-Wno-psabi", "-std=c++14", "-pthread"],
8 "cflags_cc": ["-Wall", "-Wno-psabi", "-pthread"],
9 "sources": ["./source/lib.c", "./source/lib.h", "./source/main.c"],
10 "include_dirs": [
11 "<!(node -p \"require('node-addon-api').include_dir\")",
12 "../node_modules/node-addon-api",
13 "node_modules/node-addon-api",
14 "/usr/include/node",
15 "/usr/local/include/node",
16 ],
17 "dependencies": ["<!(node -p \"require('node-addon-api').gyp\")"],
18 "defines": ["NAPI_CPP_EXCEPTIONS"],
19 }
20 ]
21 }
~
I'd like to get some help if im missing something to do
This:
"<!(node -p \"require('node-addon-api').include_dir\")"
Should be:
"<!(node -p \"require('node-addon-api').include\")"
If you launch this in your root package directory:
node -p "require('node-addon-api')"
You should get meaningful output
If you are willing to use CMake.js instead of gyp, then you can add
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
to your CMakeLists.txt and clang will be able to find the headers.
For example, you can try following these steps:
Clone this example repo
cd node-addon-examples/build_with_cmake/node-addon-api
Add set(CMAKE_EXPORT_COMPILE_COMMANDS 1) to the CMakeLists.txt
npm i
cd build
cmake ..
Now when you open up node-addon-examples/build_with_cmake/node-addon-api/hello.cc, you should not get errors for napi.h or the rest of the file.

Install lisp kernel in IPython

I'm trying to install cl-jupyter. (Debian)
I've done the following steps:
install gcl (apt-get install gcl)
install sbcl (apt-get install sbcl)
run command python3 ./install-cl-jupyter.py
try to run command sbcl --load ./cl-jupyter.lisp but I get the following and don't know what to do. I've tried to choose all option, but nothing happend.
Output:
This is SBCL 1.2.4.debian, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
debugger invoked on a SB-C::INPUT-ERROR-IN-LOAD in thread
#<THREAD "main thread" RUNNING {10039CE993}>:
READ error during LOAD:
Package ASDF does not exist.
Line: 3, Column: 29, File-Position: 150
Stream: #<SB-SYS:FD-STREAM
for "file /home/ivan/all/language_packages/cl-jupyter-master/cl-jupyter.lisp"
{10039D64A3}>
Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.
restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT ] Abort loading file "/home/ivan/all/language_packages/cl-jupyter-master/./cl-jupyter.lisp".
1: [CONTINUE] Ignore runtime option --load "./cl-jupyter.lisp".
2: Skip rest of --eval and --load options.
3: Skip to toplevel READ/EVAL/PRINT loop.
4: [EXIT ] Exit SBCL (calling #'EXIT, killing the process).
(SB-C:COMPILER-ERROR SB-C::INPUT-ERROR-IN-LOAD :CONDITION #<SB-INT:SIMPLE-READER-PACKAGE-ERROR "Package ~A does not exist." {10039D9E83}> :STREAM #<SB-SYS:FD-STREAM for "file /home/ivan/all/language_packages/cl-jupyter-master/cl-jupyter.lisp" {10039D64A3}>)
update file ipython/your_kernel_name/kernel.json
from
{"language": "lisp", "display_name": "SBCL Lisp", "argv": ["sbcl", "--non-interactive", "--load", "/home/ivan/all/language_packages/cl-jupyter-master/cl-jupyter.lisp", "/home/ivan/all/language_packages/cl-jupyter-master/src", "/home/ivan/all/language_packages/cl-jupyter-master", "{connection_file}"]}
to
{
"argv": [
"sbcl","--non-interactive", "--load",
"/path/to/cl-jupyter/cl-jupyter.lisp",
"/path/to/cl-jupyter/src",
"/path/to/cl-jupyter",
"{connection_file}"
],
"display_name": "SBCL Lisp",
"language": "lisp"
}
(information from here)
Now I can see the SBCL Lisp kernel in jupyter but it doesn't work and breaks all the time when I try to write and run smth.
Please, help
I've done it! Now it works fine.
1)I forgot to install quicklisp
2) here i just put right paths to cl-jupyter.lisp, /src, /cl-jupyter:
{
"argv": [
"sbcl","--non-interactive", "--load",
"/path/to/cl-jupyter/cl-jupyter.lisp",
"/path/to/cl-jupyter/src",
"/path/to/cl-jupyter",
"{connection_file}"
],
"display_name": "SBCL Lisp",
"language": "lisp"
}

Clojurescript + Node.js 0.12.7 issue (error "process.binding('evals') No such module: evals")

I'm trying to use Node.js + ClojureScript, and I found an article for it.
http://www.mase.io/code/clojure/node/2015/01/24/getting-started-with-clojurecript-and-node/
Following the instruction to find this error:
process.binding('evals').NodeScript.runInThisContext.call(
^
Error: No such module: evals
at Error (native)
The issue seems that I need to use old version of node: https://groups.google.com/forum/#!topic/clojurescript/VneLWVpwe6o and https://github.com/kanso/kanso/issues/422
Mine is 0.12.7
pow> node --version
v0.12.7
In this case, I may need to use old version of node, but better yet, is there a way to bypass this issue? If none exists, how to use the old version of node.js in Mac OS X?
Edit
Following https://github.com/creationix/nvm, I could install 0.10.32 version of node.js.
pow> nvm install 0.10.32
pow> node --version
v0.10.32
However, it gives me another error message:
pow> node entrypoint.js
Hello world!
/Users/smcho/Desktop/clojurescript/pow/out/server/cljs/core.js:12133
var fixed_arity = f.cljs$lang$maxFixedArity;
^
TypeError: Cannot read property 'cljs$lang$maxFixedArity' of null
Edit2
The error was because I forgot to update the core.cljs module to include ((set! *main-cli-fn* -main). It's mentioned in the original article, together with https://groups.google.com/forum/#!topic/clojurescript/DYpsiCmsyIs and https://github.com/clojure/clojurescript/wiki/Quick-Start#running-clojurescript-on-nodejs.
From the post, there are two ways to make it working, with Mac OSX, the two approaches require different version of node.js, and this is not clearly explained in the post.
The version that works with old node.js
_project.clj
(defproject pow "0.1.0-SNAPSHOT"
:description "FIXME: write this!"
:url "http://example.com/FIXME"
:dependencies [[org.clojure/clojure "1.6.0"]
[org.clojure/clojurescript "0.0-2725"]]
:node-dependencies [[source-map-support "0.2.8"]]
:plugins [[lein-cljsbuild "1.0.4"]
[lein-npm "0.4.0"]]
:source-paths ["src" "target/classes"]
:clean-targets ["out/server/pow" "out/server/pow.js"]
:cljsbuild {
:builds [{:id "server"
:source-paths ["src/server"]
:compiler {
:main pow.core
:output-to "out/server/pow.js"
:output-dir "out/server"
:optimizations :none
:target :nodejs
:cache-analysis true
:source-map true}}
]})
entry.js
// entrypoint.js
require("./out/server/goog/bootstrap/nodejs");
require("./out/server/pow");
require("./out/server/pow/core");
Run the script that executes the old node.js
#!/bin/bash
lein new mies pow
cd pow
cp ../_project.clj project.clj
mkdir src/server
mv src/pow src/server/
lein cljsbuild once
cp ../entrypoint.js .
/Users/smcho/.nvm/v0.10.32/bin/node entrypoint.js
The version that works with new node.js
Modify the _project.clj
:optimizations :simple <-
:source-map "out/server/pow.js.map" <-
Run first part of runme.sh
lein new mies pow
cd pow
cp ../_project.clj project.clj
mkdir src/server
mv src/pow src/server/
MOdify core.clj
(ns pow.core
(:require
[clojure.browser.repl :as repl]))
(enable-console-print!)
(defn -main []
(println "Hello world!"))
(set! *main-cli-fn* -main)
Then the second part of shell script
cd pow
lein cljsbuild once
node out/server/pow.js
One more note
I wanted to use ClojureScript/Node.js in order to test clojureScript code without using web browsers. I found LightTable, and
a good tutorial about it. All I need to is open the LightTable, connect to LightTable UI as an output, then execute the script. So, I have much less reason to use ClojureScript/Node.js as of now.
I fixed this with two steps:
1) Declaring a main function
(ns testproj.core
(:require
[clojure.browser.repl :as repl]))
(enable-console-print!)
(defn -main []
(println "Hello world!"))
(set! *main-cli-fn* -main)
2) Setting optimizations: simple in my project.clj, as noted at the very bottom of this blog post. For reasons unknown to me, optimizations: none breaks things.

Resources