I am experimenting with the 2htdp/planetcute library given in racket's documentation.
http://docs.racket-lang.org/teachpack/2htdpPlanet_Cute_Images.html
When I try to use its objects like "character-boy". It gives me that the dynamic-require is set to #f instead of 0.
So, there is a procedure called:
(dynamic-require mod provided)
Where, mod = module path and provided = value.
So, I ran this:
(define path (string->path /usr/shared/...../character-boy.rkt))
(dynamic-require path 0)
And then, I was able to use character-boy which returned an image. I am not able to find a procedure that does this for all .rkt files in a folder.
There are like 40-50 .rkt files and it looks like I have to write 40-50 dynamic-require procedures. Is there a simple folder dynamic-require method???
Update: this problem is now fixed in the latest version of Racket (by this commit: https://github.com/plt/racket/commit/414507699ba8f71a7b3630b833a4b4582a49dd57). You should be able to just use require normally.
If you'd like to try the fix, you can download a pre-release build from one of the build sites linked from here: http://pre.racket-lang.org/
Or you can wait until Racket v6.0.1 is released in a few weeks.
Related
So, basically, I'm trying to register a local collections collects/ directory containing modules that I don't want to be global (e.g. not in /usr/share/racket/collects) for the interpeter to use.
However, in doing this, I think I've ran into a problem where I can set the path using something like: scheme_set_collects_path(scheme_make_path("/hardcoded/absolute/path/to/collects")); but then it appears to clobber the system-wide racket collections (error is encountered where it tries to interpret the module header #lang racket - I think).
I can't give an exact rundown since I've since scrapped major contextual elements of this, so all I can really ask is: is it even possible to embed Racket such that you can interpret local source files?
I've looked at the header files and seen scheme_init_collection_paths_post, which allows you to specify pre and post paths for collections. However, I don't know if these paths completely clobber any defaults, or how do pass an empty path to pre.
Currently my idea is to register a local collections path in the same folder as my executable and dynamically require functions from local collections. So I must register a path without messing up the defaults (since doing short-form #lang racket requires "racket" collection).
I'm trying to achieve this:
((dynamic-require ''mypackage/mymodule 'myfunction))
where 'myfunction is provided by 'mymodule.
I've not quite wrapped my head around how you actually use the scheme_* functions, so I've done this:
Scheme_Object* a[2];
a[0] = scheme_intern_symbol("mypackage/mymodule");
a[1] = scheme_intern_symbol("myfunction");
Scheme_Object* func = scheme_dynamic_require(2, a);
scheme_apply(func, 0, NULL);
I don't believe that's actually how you'd go about dynamically requiring functions properly but I vaguely copied it from the dynamic require Racket REPL example.
The error I'm getting now is:
standard-module-name-resolver: collection not found
for module path: mypackage/mymodule
collection: "mypackage"
in collection directories:
context...:
show-collection-err
standard-module-name-resolver
SIGSEGV MAPERR si_code 1 fault on addr 0xd8
[1] 7102 abort (core dumped) ./main
Ignore the fact I've called the collection "mypackage". This error is the most recent error. Previously, it could resolve the local collections (I've basically been doing raco pkg install --link mypackage and then copying that into a local collects/ folder - since I know installing packages compiles them) but it wouldn't be able to load any "racket" modules (such as the one required by #lang racket).
So, how do you register an extra - local - collections directory for Racket's interpreter?
I'm working on a Racket script (on a Linux machine) that requires the math/number-theory library. My entire script at the moment is thus:
#!/usr/bin/racket
(require math/number-theory)
Yes, it's literally just requiring the library.
When I try to run it, I get an error that reads "expected a `module' declaration found: something else".
However, when I actually start up Racket in the terminal like so:
/usr/bin/racket
and enter (require math/number-theory) in the command line, it treats it like it's totally valid.
What's going on here?
Make sure the top of your racket files contains a #lang statement as well.
In other words, you need this at the top of the file:
#!/usr/bin/racket
#lang racket
I need to use a PLT-scheme library that only runs on a very old version of DrScheme (DrScheme v103p1), which I think is from at least 15 years ago.
The problem I am having is that I can't figure out how to use the library in my code because aparently the "require" function from modern racket didn't exist back then. What do I have to do to use a library then? All I know for now is that the file containing the definitions I want resides on "C:\Program Files\PLT\collects\mzlib\spidey.ss".
I tried using (require "spidey.ss") and (require "spidey") but both failed with a reference to unidentified identifier: required error.
You can use require-library to load things from the standard library:
http://download.plt-scheme.org/doc/103p1/html/mzscheme/node157.htm
(require-library "spidey.ss")
You can also use the support facilities (load and friends) to load single files. You need to use absolute paths though or else its going to search relative to your current working directory.
http://download.plt-scheme.org/doc/103p1/html/mzscheme/node149.htm
(load "C:/Program Files/PLT/collects/mzlib/spidey.ss")
Since MrSpidey is integrated into DrScheme, open DrScheme and then follow these instructions:
http://download.plt-scheme.org/doc/103p1/html/mrspidey/node4.htm
I was looking for a method to show a list of filenames in a directory, and then select one of them.
I found this:
https://github.com/lawlist/dired-read-file-name and it seemed promising, so I copied it to my emacs direcory and tried:
(require 'dired-read-file-name)
but I get error
error: Required feature `dired-read-file-name' was not provided
require is not going to work because the source of dired-read-file-name.el does not have a provides expression. You might want to add:
(provide 'dired-read-file-name)
add the end of the file.
Alternatively, you can just load or more low-level load-file.
Also have a look at this.
In Common Lisp, is there a way to get the path to a compiled file (something like current-directory)?
The file is not inside the current-directory folder.
This ought to be a comment but I'm going to give some code examples that might help the original poster along.
First of all, you need to be a little more clear about what you want to do. What is the problem you're trying to solve?
Secondly, here are a couple of examples which could be useful:
*default-pathname-defaults* usually set to the directory the CL image was started up in:
* *default-pathname-defaults*
#P"/Users/aerique/"
merge-pathnames allows you to construct new pathnames:
* (merge-pathnames "lib/misc" *default-pathname-defaults*)
#P"/Users/aerique/lib/misc"
* (merge-pathnames "lib/misc/" *default-pathname-defaults*)
#P"/Users/aerique/lib/misc/"
asdf:system-source-directory returns the path to a system loaded with ASDF:
* (asdf:system-source-directory :linedit)
#P"/Users/aerique/quicklisp/dists/quicklisp/software/linedit-20111203-git/"
Also see the linked ASDF manual for more useful file and system functions.
*load-truename* resp. *load-pathname* gives you what you need.
http://www.lispworks.com/documentation/HyperSpec/Body/v_ld_pns.htm
Perchance you want compile-file-pathname, which gives you the destination where compile-file would write into.
It'd help if you provide more context on what you're trying to achieve.
If you want get the pathname whitout use ASDF function, but you need also attend the users that use ASDF, you can use like this:
(defmacro project-pathname ()
(let ((path (or *compile-file-pathname* *load-truename*)))
`(progn ,path)))
It's necessary because the ASDF stores in one "/home/you/.../.cache/..." directory, and you need capture the pathname in compilation time with one macro.
You can use:
*default-pathname-defaults*
Please see http://cybertiggyr.com/gene/pathnames-0/node11.html