about racket : #lang not enabled - scheme

I've got to learn how-to-design-program for a while.But once I started to use my Emacs to learn htdp, I met some problem.
THE PROBLEM IS THAT:
I typed #lang racket , but it just show:
> stdin::7: read: #lang not enabled in the current context
context...:
/usr/share/racket/collects/racket/private/misc.rkt:87:7
> racket: undefined;
cannot reference undefined identifier
context...:
/usr/share/racket/collects/racket/private/misc.rkt:87:7
And I use 'require' to load path.
stdin::30: cannot open module file
module path: #<path:/Desktop/htdp/convert.rkt>
path: /Desktop/htdp/convert.rkt
system error: No such file or directory; errno=2
context...:
standard-module-name-resolver
/usr/share/racket/collects/racket/private/misc.rkt:87:7
Also it can not work.
Can you help me to solve it?
P.S my system is Fedora20.

When you're running a racket script from the console, you shouldn't need to define the language on the first line. This flag
racket -I <language>
can be used to specify a language when running from the command line. #lang racket should be the default, so just remove the line and run your script from the command line using the racket command.

from the link https://docs.racket-lang.org/guide/Module_Syntax.html#%28part._hash-lang%29
it says:
The #lang at the start of a module file begins a shorthand for a module form, much like ' is a shorthand for a quote form. Unlike ', the #lang shorthand does not work well in a REPL, in part because it must be terminated by an end-of-file, but also because the longhand expansion of #lang depends on the name of the enclosing file.

Related

How to provide full path in require in racket?

Trying to have access to functions from another file. Placed (provide (all-defined-out)) inside the other file. Now trying to actually refer to it using full path:
(require “C:\Users\functions.rkt”)
returns this error: #%require: bad require spec in: “C:Usersfunctions.rkt”
(require "C:\Users\functions.rkt")
returns this error: read-syntax: no hex digit following \U
There are two syntax errors in this snippet:
(require “C:\Users\functions.rkt”)
For starters, the double quote characters are incorrect. And you must escape the backslashes, and as Ryan points using file is mandatory. Try this:
(require (file "C:\\Users\\functions.rkt"))

emacs + comint-dynamic-complete-filename after '='

Editing a Bash script I want to assign a filename to a variable.
E.g. inputfile=foo.txt
With std. settings I can't complete the filename without first inserting a space after the '='.
Is there any solution to this?
First of all, comint-dynamic-complete has been obsolete since Emacs 24.1. The replacement function is completion-at-point.
Now, if you starting looking at what completion-at-point actually does in a shell script buffer, you'll eventually end up in comint anyway. In particular, the function comint--match-partial-filename looks promising for an explanation of the behavior you described.
If I read that correctly, the problem here is that "=" is considered a valid part of a filename, at least on POSIX-like systems (see variable comint-file-name-chars). So, the completion mechanism is trying to complete the filename "inputfile=/..." which it can obviously not find.
If you never use a "=" in your filenames (or you use it so rarely that the working completion outweighs other downsides), you may want to consider doing something like (setq comint-file-name-chars "[]~/A-Za-z0-9+#:_.$#%,{}-") in the shell script mode hook (if you are on a POSIX system; on Windows it would look slightly different).
Hope that helps.
You can use bash-completion assuming your not on windows. It just requires a slight modification to work in sh-mode since it uses a comint function to determine the current completion candidate.
I like this because, in addition to completing filenames there, it also will give you all the nice readline completion like command line switches, etc. Here is an example setup using company, but you could remove the company stuff, since all you really need is to add the modified completion-at-point function.
;; required packages: company bash-completion
(eval-when-compile
(require cl-lib))
;; locally redefine comint-line-beginning-position so bash-completion
;; can work in sh-mode
(defun sh-bash-completion ()
(cl-letf (((symbol-function 'comint-line-beginning-position)
#'(lambda ()
(save-excursion
(sh-beginning-of-command)
(point)))))
(let ((syntax (syntax-ppss)))
(and (not (or (nth 3 syntax)
(nth 4 syntax)))
(bash-completion-dynamic-complete)))))
;; put this in your sh-mode hook
(defun sh-completion-setup ()
;; add capf function
(add-hook 'completion-at-point-functions
'sh-bash-completion nil 'local)
(company-mode)
(make-local-variable 'company-backends)
;; use company completion-at-point
(delq 'company-capf company-backends)
(cl-pushnew 'company-capf company-backends)
(setq-local company-transformers
'(company-sort-by-backend-importance)))
(add-hook 'sh-mode-hook 'sh-completion-setup)

how to debug Clojure file with arg list

I am new to Clojure and want to debug a Clojure file abc.clj that will take user arguments. To run the file, i will do
lein run [arg1 arg2 ..]
I have tried emacs-cider and lighttable, but haven't found a way to input user argument from the beginning.
Maybe you can try the Debux library, and use your REPL to observe results. Seems to me that Clojure is really about the REPL and interactive development.
If I understand what you're trying to do, you should be able to sprinkle debug macros (dbg) throughout your code, then run your code with whatever changes to your args. The various results from the dbg macros will show in your REPL. I'm not sure if you can do this straight from lein, however.
From the README page:
Basic usage
This is a simple example. The macro dbg prints an original form and
pretty-prints the evaluated value on the REPL window. Then it returns
the value without interfering with the code execution.
If you wrap the code with dbg like this,
(* 2 (dbg (+ 10 20))) ; => 60
the following will be printed in the REPL window.
REPL output:
dbg: (+ 10 20) => 30

How can I specify the package name when launching a Lisp program from the command line?

I'm calling a Lisp function (and a few other thing) from a shell script. For brevity, below is relevant part of the script :
./gcl -load /tmp/calendrica-3.0.cl -batch -eval '(format T "~a"
(CC3::sunset (CC3::fixed-from-gregorian (CC3::gregorian-date 1996
CC3::february 25)) CC3::jerusalem))'
728714.7349874675
The above code works fine but I had to append the package name CC3 for every symbol that is used; which makes the code unwieldy and hard to type.
I tried to simplify it like so, using use-package :
./gcl -load /tmp/calendrica-3.0.cl -batch -eval '(format T "~a"
(use-package "CC3") (sunset (fixed-from-gregorian (gregorian-date 1996 february 25)) jerusalem))'
Much easier to read and type, but unfortunately it doesn't work. I've tried all sorts of ways to include the use-package directive but so far no success.
Is it even possible to include a use-package directive while launching a Lisp program via the GNU Common Lisp's (gcl) load directive?
Update:
The solution is to use multiple evals as suggested by the accepted answer.
./gcl -load /tmp/calendrica-3.0.cl -batch -eval
'(use-package "CC3")' -eval '(format T "~a" (sunset
(fixed-from-gregorian (gregorian-date 1996 february 25)) jerusalem))'
Maybe you could use multiple eval, here is what I do with sbcl.
#!/bin/sh
sbcl --noinform \
--eval '(load "boot.lisp")' \
--eval '(in-package #:my-pkg)' \
--eval "(do-something-useful)" # do-something-useful is in my-pkg
It's maybe possible to do that but it will be ugly.
If you give it a form form evaluation, it will read the form first. Thus it then is too late during evaluation to change the reader (telling new packages, ...). Thus it needs to be done before.
CL-USER 1 > (eval (read-from-string "(foo::bar)"))
Error: Reader cannot find package FOO.
Better:
CL-USER 5 > (eval '(progn (defpackage foo (:use "CL"))
(read-from-string "(foo::bar)")))
(FOO::BAR)
So, if you want to pass a single form to eval, you would write which first creates the package and then reads/evals from a string, which is encoded in the form. Tricky.
Alternatives:
maybe the Lisp allows at startup multiple -eval forms? Do whatever you need to initialize Lisp to know about the packages in the first -eval form. Then have the code to execute in the second form.
write a file and put the necessary forms there. Load it. Since a file can contain multiple forms, you can have DEFPACKAGE, IN-PACKAGE or similar on top and then have the rest of the code in the file depending on it.

How to insert white space in a file path in .emacs file?

I'm trying use mit-scheme in emacs but I can't get passed that problem...
The problem is I don't know how to add white spaces in a file path in .emacs file
So far I've tried
(setq scheme-program-name
"/Applications/MIT:GNU\ Scheme.app/Contents/Resources/mit-scheme")
(require 'xscheme)
and
(setq scheme-program-name
"/Applications/MIT:GNU Scheme.app/Contents/Resources/mit-scheme")
(require 'xscheme)
but the outputs I get is
Can't exec program: /Applications/MIT:GNUScheme.app/Contents/Resources/mit-scheme
Can't exec program: /Applications/MIT:GNU
because there is a white space missing in the path..
I think this is not possible using the existing functions, due to the way scheme gets called. The function run-scheme contains an explicit call to the function split-string-and-unquote on the scheme program name. As a consequence, the path to the scheme program will always be split at the first space. This means it is impossible to use a path with a space in it.
This is a bug that should be reported to the maintainers I think.

Resources