I have a file euler.rkt in my current working directory.
How do I load it as a module?
-> (require euler)
; readline-input:20:9: euler: standard-module-name-resolver: collection not
; found: "euler" in any of: (#<path:/home/ben/.racket/5.2.1/collects>
; #<path:/home/ben/racket/collects>) in: euler [,bt for context]
->
Should I add my directory to collects?
If so, what is the correct way to do it?
Try this:
(require "euler.rkt")
In addition to just using the path, as #soegaard mentions, you can also use raco link to set up a collection for your file.
Related
What is Racket's equivalent for viewing and changing the working directory of a process like pwd and cd?
Use current-directory.
Passing no arguments returns the current working directory. Passing a path changes the working directory to that path.
Here's an example for the REPL that prints the current directory, then changes to the parent directory:
> (current-directory)
#<path:/home/sage/>
> (current-directory (build-path (current-directory) ".."))
; now in /home
Note that path is a type-object in racket. And because in Racket current-directory does not actually change the environment path but only changes the current-directory path value, if you do this:
> (current-directory "/somepath/thatdoesnt/exist/") ; now in /somepath/thatdoesnt/exist
Racket will not throw an error. You'll only get an error when you try to do something with the path object itself.
such as:
> (directory-list (current-directory)) ; directory-list: could not open directory ; path: /somepath/thatdoesnt/exist/ ; system error: No such file or directory; errno=2 ; [,bt for context]
I download Semantic Network Processor project:
http://digital.cs.usu.edu/~vkulyukin/vkweb/software/snp/snp.html
and following it's read me,
By using CLISP interpreter I change the directory to the folder,
and do the following:
[3]> (load "snp-loader.lisp")
;; Loading file snp-loader.lisp ...
;; Loaded file snp-loader.lisp
T
[4]> (in-package "USER")
<PACKAGE COMMON-LISP-USER>
[5]> (snp-load-everything)
**- MAKE-PATHNAME: Illegal :DIRECTORY argument "D:\\snp-stable\\"**
The following restarts are available:
ABORT :R1 Abort main loop
can anybody tells me what's wrong or how I can fix it in order to make the project run?
In snp-loader.lisp, instead of directory-namestring, you need to call pathname-directory:
(defparameter parm-snp-load-dir
(pathname-directory *load-truename*))
But then another problem occurs later, when defining a method for expectations-on-token. In c-snp-with-vars.lisp, the docstring is malformed, which triggers an error. Join both strings:
(defmethod expectations-on-token ((this-snp c-snp-with-vars) (tok t))
"Overloaded expectations-on-token to process variables and tests.
Get all expectations waiting for the token tok."
`(,#(find-static-expectations this-snp tok)
,#(find-dynamic-expectations this-snp tok)))
Reload the snp-loader.lisp file, and retry (snp-load-everything). It should load properly.
Edit. I contacted the original author; the latest version of the code is now hosted on GitHub at https://github.com/VKEDCO/AI/tree/master/NL/SNP.
I'd like to be able to only import namespaced items from a module in Racket. The prefix-in function does allow me to access functions from the module using the prefix, but it doesn't hide the old name.
$ racket
Welcome to Racket v6.6.
> (require (prefix-in tcp: racket/tcp))
> tcp-accept
#<procedure:tcp-accept>
> tcp:tcp-accept
#<procedure:tcp-accept>
Is there a simple way to hide the unprefixed names?
The prefix-in form only imports the prefixed names, not the unprefixed ones. However, the racket language includes the racket/tcp module by default, so it is already imported when the REPL starts up. If you use #lang racket/base, instead, then tcp-accept won’t be imported, so the prefixed import will be the only imported identifier. You can simulate this using the -I racket/base option in the REPL:
$ racket -iI racket/base
Welcome to Racket v6.7.0.4.
> (require (prefix-in tcp: racket/tcp))
> tcp-accept
; tcp-accept: undefined;
; cannot reference undefined identifier
; [,bt for context]
> tcp:tcp-accept
#<procedure:tcp-accept>
I cannot make emacs to jump to next-error, previous-error, first-error in vhdl-mode.
I am using FSF Emacs 23.3.1 with recent vhdl-mode 3.33.28 under ubuntu.
I can compile with Modelsim and I get compiler error list:
-- Loading package standard
-- ...
-- Compiling entity foo
** Error: path/foo.vhd(22): (vcom-1136) Unknown identifier "std_olgic".
I tried to adapt error regexp (in compiler-setup) to the simplest one:
\*\* Error: \([a-zA-Z\/_.]*\)(\([0-9]*\)).*
When I use it this way I can see that it parses errors correctly:
sed "s/\*\* Error: \([a-zA-Z\/_.]*\)(\([0-9]*\)).*/\1 \2/" ...
path/foo.vhd 22
I changed "File subexp index" and "Line subexp index" respectively to 1 and 2 but still I cannot jump around errors.
The following config resolves this bug for me
'(vhdl-compile-use-local-error-regexp t)
(add-to-list 'compilation-error-regexp-alist '("** Error: \\(.+\\)(\\([0-9]*\\)):" 1 2))
In Emacs regexps, you need to double-escape parens in a string (explanation). Try something like this: \*\* Error: \\([a-zA-Z0-9/_.]+\\)(\\([0-9]+\\)).*
Sorry to bump an old topic but I just ran into this issue and got things to work out for me.
Here are the settings I used to get it to work:
Regexp:
\(ERROR\|WARNING\|\*\* Error\|\*\* Warning\)[^:]*:\( *[[0-9]+]\)? \(.+\)(\([0-9]+\)):
File subexp index: 3
Line subexp index: 4
Vhdl Compile Use Local Error Regexp (under Vhdl Compile group): Off
And here's my story about it:
http://www.velocityreviews.com/forums/t957495-emacs-vhdl-mode-next-error-previous-error-and-first-error-are-not-working.html
:P
Hope this helps!
In common lisp I can do this:
src-> (defmacro macro-hello ()
`"hello")
(eval '(macro-hello))
no problem.
In clojure:
(defmacro macro-hello []
`"hello")
(eval '(macro-hello))
gives me an error. Have I done something wrong?
Clojure Error:
Exception in thread "main" java.lang.Exception: Unable to resolve symbol: macro-hello in this context (NO_SOURCE_FILE:12)
at clojure.lang.Compiler.analyze(Compiler.java:4340)
at clojure.lang.Compiler.analyze(Compiler.java:4286)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:2767)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:4498)
at clojure.lang.Compiler.analyze(Compiler.java:4325)
at clojure.lang.Compiler.analyze(Compiler.java:4286)
at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:3862)
at clojure.lang.Compiler$FnMethod.parse(Compiler.java:3697)
at clojure.lang.Compiler$FnMethod.access$1100(Compiler.java:3574)
at clojure.lang.Compiler$FnExpr.parse(Compiler.java:2963)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:4494)
at clojure.lang.Compiler.analyze(Compiler.java:4325)
at clojure.lang.Compiler.eval(Compiler.java:4530)
at clojure.core$eval__3990.invoke(core.clj:1728)
at com.yourcompany.defpackage$_main__4.invoke(defpackage.clj:12)
at clojure.lang.AFn.applyToHelper(AFn.java:171)
at clojure.lang.AFn.applyTo(AFn.java:164)
at com.yourcompany.defpackage.main(Unknown Source)
Caused by: java.lang.Exception: Unable to resolve symbol: macro-hello in this context
at clojure.lang.Compiler.resolveIn(Compiler.java:4682)
at clojure.lang.Compiler.resolve(Compiler.java:4628)
at clojure.lang.Compiler.analyzeSymbol(Compiler.java:4605)
at clojure.lang.Compiler.analyze(Compiler.java:4307)
... 17 more
Java Result: 1
[Edited]: added ending double quote
Your code works for me.
user> (defmacro macro-hello [] `"hello")
#'user/macro-hello
user> (eval '(macro-hello))
"hello"
This is via bleeding-edge Clojure. "Unable to resolve symbol" means it can't find the macro called macro-hello in the current namespace. Are you running this from the REPL or in a source file? I typed your statements at a REPL literally.
Not sure if this is a cause of problems for you, but please note the difference between ` and ' in Clojure. ` does namespace resolution and ' doesn't.
user> `macro-hello
user/macro-hello
user> 'macro-hello
macro-hello
This is different from Common Lisp's behavior. Backtick-quoting a String like `"hello" doesn't make much sense, since Strings don't belong to namespaces, but it also doesn't hurt anything.
(I'm assuming you made a typo in your Clojure code, with the missing double-quote.)
I like to work out of /opt on Mac and Linux boxes. To get the Clojure source. (% is Unix prompt)
% cd /opt
% git clone git://github.com/richhickey/clojure.git; #From Unix command line, you'll have an /opt/clojure dir
% cd /opt/clojure
% /opt/netbeans-6.7.1/java2/ant/bin/ant; # Run ant. It ships with Netbeans.
% cd /opt; # mkdir /opt if it's not there.
% git clone git://github.com/richhickey/clojure-contrib.git; # Get contrib
% /opt/netbeans-6.7.1/java2/ant/bin/ant -Dclojure.jar=../clojure/clojure.jar ; # Tell ant where clojure.jar is located
I rename jars to clojure.jar and clojure-contrib.jar
Copy these jars to your Netbean's project lib directory.