I am working on the zh_CN l10n for guix, and it uses scheme-format messages. I tried to look for a way like "Only %2$d bytes free on '%1$s'." in c-format to specify the nth operand for the string formatter in scheme-format, but was somehow confused by the description in SLIB manual section Format Specification.
So, is there a way to achieve some similar effect with slib's (format fmt ..) that I can use with GNU gettext?
I should have read the document more carefully -- apparently there is a way to jump arguments:
~* Argument Jumping (jumps 1 argument forward).
~n* jumps n arguments forward.
~:*
jumps 1 argument backward.
~n:*
jumps n arguments backward.
~#*
jumps to the 0th argument.
~n#*
jumps to the nth argument (beginning from 0)
Related
This is valid Scheme
1 2 3
and returns 3. But this is not valid
(1 2 3)
and neither is this valid
(1) (2) (3)
It makes sense that the last two are not valid. But I don't see how the first one should be valid? Can someone please explain?
Probably, the REPL of your implementation is reading a non-empty sequence of expressions and evaluating all of them and giving the sequence of results. (I believe that this behavior of the REPL is implementation specific. R7RS does not mention it in its ยง5.7. It might vary with other implementations of Scheme and I never used it; I agree with coredump's answer that it may be a fancy and useful feature)
Scheme is able to return and handle several values, e.g. with call-with-values & values ; see also this
So technically 1 2 3 is not a single expression, but a sequence of three expressions. A call to (read) won't give you such a sequence. And on guile 2 on Linux (+ 2 (read)) 55 66 gives immediately two results 57 66, not three (after waiting for input).
Read also about call/cc, continuations, and CPS. There might be some indirect relation (how does your REPL deal internally with them when (read)ing expressions....)
The REPL is reading multiple forms in sequence (this is also how Common Lisp implementations work). Given that the user entered multiple forms, what else could happen?
displaying an error would be correct, but unhelpful
discarding previous/next forms would be confusing
IMHO the behavior of reading all the given forms as-if they were in an implicit progn is the most useful for the user. It is also consistent with how files are read, and allow you for example to paste the content of a file directly into the REPL.
The first one is valid because it is considered a simple expression. Scheme doesn't do anything with it and just echoes it back to you. This is true not only for numbers, but also for all constants including strings, symbols and even lists (if you quote them to create an actual list rather than a function call). For ex. if you type in '(1 2 3), it will be just echoed back to you without being interpreted.
The way scheme, and generally other lisps, evaluate expression can be described by two broad rules (and this is probably a naive interpretation):
If the entered expression is a constant (a string, number, symbol, list or something else), the constant itself is the value. Just echo it back.
If the expression is of the form (procedure arg1 ... arg-n), find the value of procedure, evaluate or find the values of all the arguments (arg1 to arg-n), and apply procedure to the arguments.
More details are available at Evaluating Scheme Expressions chapter in the the book The Scheme Programming Language 4e.
The key observation is that it is not allowed to put in extra parenthesis in Scheme. In (+ 1 2) the expression + is evaluated and the result is a plus-function. That function is applied to 1 2 and you get the result 3.
In your example (1) means evaluate 1 and the result is 1. Then apply 1 to no arguments. And since 1 is not a function you will get an error.
In the example (1 2 3) your system attempts to apply 1 to the arguments 2 and 3 and get an error.
In short: Parenthesis in arithmetics is used to group an operation - in Scheme it means function application.
Finally: 1 2 3 is not a single expression but three expressions. The last of which evaluates to 3.
Short story: Given a position value in the buffer say, 12345, how to take the cursor to the position directly
Long story: when i debug my emacs initial boot messages, it prints an error message as,
eval-buffer(#...........................) ; Reading at buffer position 19352
The fact, no line numbers are printed & only the position value is there makes my navigation tough. any clues, to make my cursor to jump to the position 19352?
Simply
(goto-char 19352)
See documentation
To enter Lisp code interactively, the eval prompt is M-:
You want to use that using the command goto-char, which by default is bound to M-g c. So you can do
M-g c 19352 RET
or, if you forget the binding,
M-x goto-char RET 19352 RET
Example:
conditions([-on(a, b)]).
I have searched tirelessly but fruitlessly for the meaning of this and the + prefix. You are my last hope.
No context is provided, so I'm supposing this might come from something in documentation.
If you read the introductory material in the Prolog manual (SWI, Gnu, or whichever) they describe teh conventions. The +, -, and ? are used as a convention in documentation to indicate whether an variable is an input or an output or a variable (either). For example, from the Gnu Prolog manual:
+: the argument must be instantiated.
-: the argument must be a variable (will be instantiated if the built-in predicate succeeds).
?: the argument can be instantiated or a variable.
So, for example, atom_length/2 is described as;
atom_length(+atom, ?integer)
Which means you must provide atom (it can't be a variable) and integer can either be a variable (in which case atom_length will provide a value) or it can be instantiated (in which case atom_length will indicate whether your query is true or false)`.
You don't normally use the - or + in your code in this sense, unless you really intend to have it there as part of your term. Considering the given example, it looks like it may have been an intended part of the term:
conditions([-on(a, b)]).
The list parameter consists of a term, when spelled out fully, is -(on(a,b)) (-/1 with parameter that's on/2). The - here doesn't provide any function, it just adds structure (the structure being a term with name - and parameter on(a,b)).
I wanted to see the type of the multiplication function (*), so I tapped it into the OCaml toplevel.
# (*)
However, the toplevel echoed:
(*);; 1: this is the start of a comment.
and then consumed any further input I put in. I figured that I had to get out of the comment mode by pressing Ctrl+d to send EOF. Great. But surely, I should be able to query the type of any function, including our mysterious multiplication function (*)?!
I would be incredibly disappointed if that is a limitation of the toplevel.
It does recognize *) as the end of the comment, but it's still waiting for the end of the expression. I.e. if you enter two semicolons, it will give you a syntax error and allow you to enter another expression.
To get the function * type ( * );; with spaces to distinguish it from comment symbols.
I've searched for an explanation to this but haven't found one. What do the question mark, plus sign, and minus sign that sometimes precede variable names in the description of a Prolog predicate mean?
Example:
predicate(?Variable1,+Variable2,-Variable3)
? means: This variable can be either instantiated or not. Both ways are possible.
+ means: This variable is an input to the predicate. As such it must be instantiated.
- means: This variable is an output to the predicate. It is usually non-instantiated, but may be if you want to check for a specific "return value".
Source: Chapter 4 of the SWI Prolog documentation.
+ means that Variable2 is expected to be bound (to a term, or perhaps just some variable) -- you can think of this as input to predicate/3, which the predicate won't attempt to modify in execution.
- means that Variable3 is expected to be bound by predicate/3 in it's execution -- you can think of this as output from predicate/3. This doesn't mean it can't be bound, however, particularly if you know what to expect and are checking for success, but predicate/3 is described as potentially binding (unifying) Variable3 to something.
? means that Variable1 can be either be bound (+, input) or not (-, output) - predicate/3 should deal with both cases, if it accepts either.