What is the colon (:) in Emacs lisp? - emacs

I'm not talking about keyword variables (those that are prefixed with a colon), I'm talking about just :. Example from an ielm session:
ELISP> :
:
It seems to be a variable whose value is : which makes it sort of act like a noop like it does in shell. I'm just curious if there's any documentation about it. I can't look it up with describe-variable...

: is a keyword, that is, a Lisp symbol whose print name begins with ":". It satisfies predicate keywordp.

Looks like it's just a variable whose value is : after all. I can't look it by calling describe-variable interactively but I can look it up with (describe-variable :):
:'s value is :
Documentation:
Not documented as a variable.
Edit: no, it's not a variable. See the accepted answer.

Related

What is the function "defs" in Lisp?

In the "Dictio" file, located at the link "Text-only console version" of this site, I've noticed a Lisp command (?) called defs.
I assume that this is something similar to defun, but am unable to find any information on what defs does; is it used to define a function, or maybe a variable? I am looking to reproduce this code using modern techniques and it would help to know the purpose of defs.
The defs calls seem to also include more than a name before the arguments (I would expect it to read (defs name () body).
Looking at the first function in the list, there appears to be more included in this "function definition" [the word 'features' specifically] and in the third function, there is ['semantics'] included after what appears to be the name of the function (before the arguments).
DEFS is defined by the software in the file SYSCOM.
It is a FEXPR, which is a function which gets the arguments unevaluated. Common Lisp has no such feature. It uses macros instead.
Example use:
(DEFS \#COLOR
FEXPR (LAMBDA (A)
(EVAL (SUBST (CAR A)
'COLOR
'(OBJECT
(MARKERS\: (\#PHYSOB COLOR)
PROCEDURE\: ((\#COLOR *** COLOR)))))))
PRIORITY 192.
SYS (\#PROPERTY))
Here you have a symbol #COLOR. It gets a function (actually a FEXPR) defined under this name. Also it puts a PRIORITY and SYS onto the property list of the symbol. Thus DEFS is used to define symbols with functions and properties in one defining form.

order of calling expressions within a defun*

Tried to use the persp-mode https://github.com/Bad-ptr/persp-mode.el/blob/master/persp-mode.el to retrieve the emacs windows session after restart. Unable to get it working.
So trying to understand the datastructure used to store the state of the emacs by reading the source code.
The following is the function which is used to store the session state.
(defun* persp-save-state-to-file (&optional (fname persp-auto-save-fname)
(phash *persp-hash*)
respect-persp-file-parameter)
(interactive (list (read-file-name "Save perspectives to file: "
persp-save-dir)))
In the above function two unusual things are observed using edebug (unusual according to my current understanding of elisp).
The optional argument expressions are evaluated.
The expression "(interactive..." is evaluated first and then the optional argument expressions are evaluated.
Any ideas how to debug the code. Also the emacs documentation says "defun*" is related to common-lisp, but no further information is available in emacs docs on how defun* is different from defun. Is there a quick tutorial oh what defun* does without having to learn common-lisp.
Emacs says:
Define NAME as a function. Like normal `defun', except ARGLIST allows
full Common Lisp conventions, and BODY is implicitly surrounded by
(cl-block NAME ...).
Common Lisp arglists provide optional, rest, keyword and aux arguments. Historically this comes from Lisp Machine Lisp and Mumble - two earlier Lisp dialects.
For details see: http://www.gnu.org/software/emacs/manual/html_node/cl/Argument-Lists.html
Have a look at this post for a simplistic snippet explaining
how optional works. The gist is that e.g. persp-auto-save-fname will be the value of fname
if none is given.
And obviously interactive has to be run first, because it provides the arguments.
So if interactive doesn't provide a value for fname it will be persp-auto-save-fname.

What is the ":" function in Racket?

I'm looking at the source code here
which has expressions like
(: track->notes (MIDITrack -> (Listof Note)))
what is the : function?
I suspect it has something to do with contracts, but can't find a reference in the documentation.
:, in this context, means "has type". It is part of the Typed Racket extension, which adds static type checking to the language.
Your example states that the function track->notes accepts a MIDITrack and returns a list of Notes.
If you want to find out more, take a look at the Typed Racket documentation.

In Emacs, how can I syntax-highlight a text in a C mode buffer matching a certain regular expression?

By default Emacs will not highlight constants, struct members, function calls etc (unless inside the definition). I am talking about C major mode here.
I want some basic highlighting, just based on text matching. For example, A word containing only upper case and underscore, [A-Z_]+, for example SOME_CONST, is a constant (unless otherwise highlighted). Similarly, I can match for [a-zA-Z_][a-zA-Z0-9_]\s( as function call; ->[a-zA-Z_][a-zA-Z0-9_]* as a struct member etc.
How can I do this emacs ?
I think the elisp function that you want is font-lock-add-keywords. I've added the following to my .emacs and gotten what I think you want for upper case words:
(font-lock-add-keywords 'c-mode '("\\<\[A-Z_\]\+\\>"))
You'd have to add a bit more to handle integer constants. Some of the documentation around this warns that if you're not intelligent about your regular expressions it can slow things down dramatically, and that you should use regexp-opt for matching multiple keywords.
The part that was a bit confusing for me is that the argument to font-lock-add-keywords can be a regular expression.

Variable passed to macro gets resolved in wrong namespace?

The Noir macro defpage is giving me a little bit of trouble. I am trying to construct a call similar to this:
(defpage [:post "some/url"] [data]
;; some stuff...
)
However, instead of using the keyword :post I would like to use a variable, like this:
(def my-method :post)
(defpage [my-method "some/url"] [data]
;; some stuff...
)
The problem is that when the macro expands, it wants to resolve the variable my-method in the compojure.core namespace instead of my own, giving me the error:
No such var: compojure.core/MY-METHOD
How can I force my-method to resolve in the current context?
I guess this is a similar problem to: How can I apply clojure's doc function to a sequence of functions
A macro can do whatever it wants with its args, so passing a naked symbol in can result in unpredictable results.
A way to solve it, but it ain't pretty:
(eval (list 'defpage (vector my-method "some/url") '[data]
; some stuff
))
Notice that my-method is not a literal here, so it gets resolved and evaluated in our own namespace first, before going into eval.
It seems, that noir is not meant to be used this way, because it takes the method argument and transforms it to the symbol in compojure.core (see https://github.com/ibdknox/noir/blob/master/src/noir/core.clj#L36). It means, that it doesn't expect a variable in this place, only literals. So I don't think you can do anything about that, except post an issue to noir...
If we look through noir/core.clj file (source), find parse-route function and reason what it does with its method argument (it is called action there), we could find that method keyword is converted to string, uppercased and resolved in compojure.core namespace. All this is done during macro expansion time. So it is not possible to use variable instead of keyword without altering noir code.
What about passing my-method along with namespace it is in:
(defpage [myns/my-method "some/url"] [data]
;;
)