I have installed A+ and set up XEmacs in Debian, using the aplus-fsf-dev and aplus-fsf-el packages; XEmacs was installed as a dependency.
I checked the A+ site (http://www.aplusdev.org/), and there seems to be nothing about running A+ on plain Emacs (and not XEmacs).
Does anyone know if there are elisp files somewhere for setting up A+ on plain (FSF) Emacs?
Thanks!
PS: So, the elisp files for XEmacs do not run on Emacs. I tried converting them, but I had to go farther and farther into the code, so I gave up.
PS2: In Emacs, when I do (require 'aplus), this is what I get:
Debugger entered--Lisp error: (wrong-type-argument arrayp (super 97))
define-key((keymap) (super 97) a-self-insert)
(let ((key ...) (apl ...)) (define-key a-minor-map (append a-modifier-list ...) (quote a-self-insert)) (define-key a-minor-map (vector ... key) (quote a-self-insert)) (aset a-key-string (char-to-int key) apl))
a-insert-map((97 . 193))
mapcar(a-insert-map ((97 . 193) (98 . 194) (99 . 195) (100 . 196) (101 . 197) (102 . 95) (103 . 199) (104 . 200) (105 . 201) (106 . 202) (107 . 39) (108 . 204) (109 . 124) (110 . 206) (111 . 207) (112 . 42) (113 . 63) (114 . 210) (115 . 211) (116 . 126) (117 . 213) (118 . 214) (119 . 215) (120 . 216) (121 . 217) (122 . 218) (49 . 161) (50 . 162) (51 . 60) (52 . 164) (53 . 61) (54 . 166) (55 . 62) (56 . 168) (57 . 169) (48 . 94) (45 . 171) (61 . 223) (92 . 220) (96 . 254) (44 . 172) (91 . 251) (93 . 253) (59 . 219) (39 . 221) (46 . 220) (47 . 175) (33 . 224) (64 . 230) (35 . 231) ...))
eval-buffer(#<buffer *load*<3>> nil "/usr/share/emacs/site-lisp/aplus-fsf-el/keyb.el" nil t) ; Reading at buffer position 3754
load-with-code-conversion("/usr/share/emacs/site-lisp/aplus-fsf-el/keyb.el" "/usr/share/emacs/site-lisp/aplus-fsf-el/keyb.el" nil t)
require(keyb)
eval-buffer(#<buffer *load*<2>> nil "/usr/share/emacs/site-lisp/aplus-fsf-el/xa.el" nil t) ; Reading at buffer position 16
load-with-code-conversion("/usr/share/emacs/site-lisp/aplus-fsf-el/xa.el" "/usr/share/emacs/site-lisp/aplus-fsf-el/xa.el" nil t)
load("xa" nil t)
(if aplus-setup-global-bindings (load "xa" nil t))
eval-buffer(#<buffer *load*> nil "/usr/share/emacs/site-lisp/aplus-fsf-el/aplus.el" nil t) ; Reading at buffer position 1373
load-with-code-conversion("/usr/share/emacs/site-lisp/aplus-fsf-el/aplus.el" "/usr/share/emacs/site-lisp/aplus-fsf-el/aplus.el" nil t)
require(aplus)
eval((require (quote aplus)))
eval-last-sexp-1(nil)
eval-last-sexp(nil)
call-interactively(eval-last-sexp nil nil)
This is because in keyb.el, there is this function:
(defun a-insert-map (akeydef)
(let ((key (car akeydef))
(apl (cdr akeydef)))
(define-key a-minor-map (append a-modifier-list (list key)) 'a-self-insert)
(define-key a-minor-map (vector '(control c) key) 'a-self-insert)
(aset a-key-string (char-to-int key) apl)))
I changed append to vconcat, and then I got an error on the last line of that function, because Emacs does not have an char-to-int function. I removed the function call and replaced by the argument ("key") itself, since I understand that Emacs will already treat that character as a number.
Then There were other not so obvious errors in other functions; most of them dealing with define-key and keymaps.
I suppose Emacs and XEmacs deal with keymaps differently?
Let the answers begin. SO wasn't really designed for a running debugging session, but here goes.
Depending on whether you want to make the same .el files loadable by both Emacs and XEmacs, you'll have to figure how you want to isolate the differences.
The most(?) portable way to define keys in Emacs is using the 'kbd macro. So, the 'define-key invocation should look something like:
(define-key a-minor-map (kbd (format "C-c %c" key)) 'a-self-insert)
I don't know what the a-modifier-list is for, but it probably can be massaged into a string to pass to 'kbd. A good introduction to 'kbd or 'read-kbd-macro can be found here. A long document on Emacs keybindings can be found here. It covers all sorts of notations for keybindings, and perhaps it would be of use to decode some of the XEmacs things.
Related
I was working on something that was clear for a while but, at some point, I wasn't able to understand.
So I know that this image represents (a b c x d):
But, what I don't get is what happens for this one:
Since there is one with nothing on it, which points to two things, how to write with parenthesis that there are two ways with b x and d a
I would write it (c((b(x))(d(a)))) but I'm not really sure about it.
Thanks for the answer, I appreciate it;
I think the useful way of thinking about these is to realise two things:
all boxes are cons cells, aka pairs;
there is a slightly unhelpful shorthand being used, and if you redraw the diagram without that shorthand it is easier to translate.
The unhelpful shorthand is that a box which is drawn like this:
is, in fact simply this:
Where () is the unique 'empty-box' object which is traditionally called nil in Lisp, but does not have a name (I think) in Scheme as a standard.
So knowing this shorthand you can take the picture you have, which is the same as this one
and unfold it to this one
So, OK, now you have this unfolded picture, you can simply write down the representation of this as text, remembering that the representation of a cons cell is simply (l . r), say, where l and r are the left and right elements, and the representation of the empty-box object is ().
I'm not going to write down the textual representation of your problem since I don't want to do your homework – I want to explain how to do your homework! – but I will write down the representation of this, say:
Well, just following the boxes we get a representation which is
((x . ()) . (y . ())
Which, oops, isn't anything like the sort of answer you need to get.
But all is not lost. Now you need to know the final thing: there are three special rules which apply to printing (or reading) trees (graphs) of conses like this.
Rule 1. A cons which is of the form (<anything> . ()) can be written s (<anything>).
Rule 2. A cons whose right hand entry (cdr) is itself a cons can have the dot elided and the right hand cons spliced in. So (x . (y . ...)) can be written as (x y . ...), for instance.
Rule 3. When writing cons trees, you usually try and apply rules 1 and 2 to minimise the number of dots in the printed representation.
So let's apply these rules to the above structure.
we start with ((x . ()) . (y . ());
we can apply rule 1 twice to each half, to get ((x) . (y));
we can now apply rule 2 once, since the right hand side of the top object is a cons, to get ((x) y). And this is like the sort of representation you are expected to provide.
As a guide when applying these rules it is best to apply them from the inside out, and to apply all the rule 1's you can followed by the rule 2's.
So in summary the approach I would suggest is:
redraw the diagram with the shorthand for () removed;
read off the cons-tree structure from it as (... . ...);
use the rules above to minimize the number of dots in the cons-tree you have written down;
profit.
Start with pairs. Every box is (x . y) with x and y being the parts the box points to. eg. for the first one it's:
(a . (b . (c . (x . (d . ())))))
Now most lisps will remove the . and the parenteses around the cdr if they can.. Eg. (d . ()) => (d) and you can apply this simplification all the way such that the above can be displayed:
(a b c x d)
A missing dot between elements and end means . (...) in my head so while I don't see them I imagine the dot notation when looking at it.
The second box notation means clearly this:
(c . ((b . (x . ())) . (d . (a . ()))))
Now you can do the trick with removing dots if the cdr has parentheses in them. I leave that for you to do since you need to do this transformation in your mind both forward and backward. eg. you should be able to look at ((e f) x (i j)) and say ((e . (f . ())) . (x . ((i . (j . ()))))) and that accessing j is cadaddr (which might not exist since it is 5 and the requirement is 4 so you can split it up to (car (cdaddr '((e . (f . ())) . (x . ((i . (j . ()))))))) ; ==> j)
You can play with https://github.com/cbaggers/draw-cons-tree
CL-USER> (ql:quickload "draw-cons-tree")
CL-USER> (draw-cons-tree:draw-tree '(c ((b (x)) (d (a)))))
[o|o]---[o|/]
| |
C [o|o]---[o|/]
| |
| [o|o]---[o|/]
| | |
| D [o|/]
| |
| A
|
[o|o]---[o|/]
| |
B [o|/]
|
X
NIL
CL-USER> (draw-cons-tree:draw-tree '(c ((b (x)) d a)))
[o|o]---[o|/]
| |
C [o|o]---[o|o]---[o|/]
| | |
| D A
|
[o|o]---[o|/]
| |
B [o|/]
|
X
NIL
CL-USER>
Transform any box diagram by recursively applying the same transformation:
[ * | * ] ---> B
|
|
v
A
becomes
( {A} . {B} )
where {A} means the diagram A transformed by the same procedure.
A special case is that [ A | / ] (writing it as a shorthand for
[ * | / ]
|
|
v
A
) is the same as
[ A | * ] ---> NIL
and a base case is {NIL} === ().
The other base case is that anything not inside a box is just as it is.
It doesn't matter which way the arrow is drawn pointing, what matters is whether it starts from the first field of a box, or from the second field.
Your last diagram thus becomes
(c . { ... })
(c . ( {...} . { ... }))
(c . ( {...} . (d . { ... })))
(c . ( {...} . (d . (a . {NIL}))))
(c . ( (b . {...}) . (d . (a . {NIL}))))
(c . ( (b . (x . {NIL})) . (d . (a . {NIL}))))
(c . ( (b . (x . ( ))) . (d . (a . ( )))))
Having transformed your box-and-pointers diagram in full, you're left with a textual string representation of it. To simplify it by removing all the excessive dots and pairs of parentheses, finally apply the rule
(A B ... . (C ...)) === (A B ... C ...) ;; NB nothing after (C ...)!
in a purely syntactical manner, repeatedly, anywhere inside the string that you can, until it can't be applied any longer. Just remove both the dot and the following pair of the matching parentheses around the last subexpression in a list together, at once. Both B ... and C ... sequences can be empty, or non-empty sequences:
(c . ( (b . (x . ( ))) . (d . (a . ( )))))
(c . ( (b . (x )) . (d . (a . ( )))))
(c . ( (b . (x )) . (d . (a ))))
(c . ( (b . (x )) . (d a )))
(c . ( (b x ) . (d a )))
(c . ( (b x ) d a ))
Or you could perform it in different order, as
(c . ( (b . (x . ( ))) . (d . (a . ( )))))
(c (b . (x . ( ))) . (d . (a . ( ))) )
(c (b . (x . ( ))) d . (a . ( )) )
(c (b . (x . ( ))) d a . ( ) )
(c (b . (x )) d a )
I've left one more step for you to perform, in both cases. The end result will be the same.
I'm trying to create a composition in dash, that does the following
- split into lines
- remove empty lines
- keep lines starting w/"N"
- return filename extension
However the code below feels clunky - wondering if anyone could help
simplify/rewrite this.
(let ((line-sep "\\\n")
(new-ind "^N ")
(sample-output "
N /dir1/file1.el
N /dir1/file2.dot
/dir1/file3.py
/dir1/file4.sql"))
(funcall
(-compose
(-partial '-map (lambda(x) (file-name-extension (nth 1 (split-string x)))))
(-partial '-filter (-partial 'string-match-p new-ind)) ; keep lines starting w/"N"
(-partial '-filter (lambda(x) (> (length x) 0))) ; remove empty lines
(-partial (-flip 'split-string) line-sep)) ; split into lines
sample-output))
After fooling around with it, it looks like the compose pipeline only works well when all the functions take the same type of argument.. I rewrote it like so, and it seems like a better fit; would like to hear comments..
(let* ((line-sep "\\\n")
(lexical-binding t)
(new-ind "^\\s-*N ")
(sample-output "
N /dir1/file1.el
N /dir1/file2.dot
/dir1/file3.py
/dir1/file4.sql")
(lines (split-string sample-output "\\\n")))
(-annotate
'file-name-extension
(-map
(-compose
(-partial 'nth 2)
(-partial (-flip 'split-string) "\\s-+"))
(--filter
(string-match-p "^\\s-*N " it)
lines))))
I'm attempting to implement coroutines in Racket LISP for a personal learning project using the scheme implementation from this accepted answer. However, when loading my .rkt file into the racket repl I get the following error:
; 3.rkt:111:18: define: not allowed in an expression context
; in: (define (run-handler) (make-generator (lambda (yield) (send
; (get-dp-data-object key) run))))
It seems to be complaining about the define(s) in this section of the code:
108 (define-syntax (define-coroutine stx)
109 (syntax-case stx ()
110 ((_ (name . args) . body )
111 #`(define (name . args)
112 (make-generator
113 (lambda (#,(datum->syntax stx 'yield))
114 . body))))))
According to the accepted answer here this exact error is not shared by Scheme and is unique to Racket when attempting defines in an expression.
The code calling (define-coroutine) seems to be:
518 ;; Qt-esque connect macro
519 (define-syntax connect-message
520 (syntax-rules ()
521 [(register src-obj-key msg-type dst-obj-key handler)
522 (register-message-handler
523 msg-type
524 (begin
525 (define-coroutine
526 (handler-accessor)
527 (if (eqv? (get-dp-data-object dst-obj-key) #f)
528 #f
529 (send
530 (get-dp-data-object dst-obj-key)
531 handler
532 (get-field args msg))))
533 handler-accessor))]))
This is my first Racket project so I'm learning a lot as I go. The (begin) above is trying to define and return a coroutine that calls an object method. I'm sure that there's lots of problems with this code snippet, but the debugger is blocking me with the above issue, stopping me from getting later errors :)
I am not nearly skilled enough in Racket, Scheme, or LISP to fix this issue, I can hardly understand this error at the moment. Can someone break down the problem for me and hopefully correct the issue so I can get this coroutine code working in Racket?
In racket, begin does not create a new scope.1 This means that anything you define inside of a begin form is still in scope outside of that form. It also means that begin doesn't change the context, and so if you are in an expression context, begin keeps that.
The define form has (roughly) the following grammar:
(define <id> <expr>)
Where <id> is the variable name, and <expr> is an expression. However, the define form itself is not an expression, so something like this is invalid:
(define x (define y 5))
And because begin doesn't change the context, this is invalid too:
(define x
(begin
(define y 5)
y))
Instead, you can use let to create a new scope. And because let itself is an expression, you can put it in define. So you could write something like:
(define x
(let ()
(define y 5)
y))
And now, x is bound to 5 as expected.
Taking this back to your original question, you had the code:
518 ;; Qt-esque connect macro
519 (define-syntax connect-message
520 (syntax-rules ()
521 [(register src-obj-key msg-type dst-obj-key handler)
522 (register-message-handler
523 msg-type
524 (begin
525 (define-coroutine
526 (handler-accessor)
527 (if (eqv? (get-dp-data-object dst-obj-key) #f)
528 #f
529 (send
530 (get-dp-data-object dst-obj-key)
531 handler
532 (get-field args msg))))
533 handler-accessor))]))
I'm assuming register-message-handler is a function, and therefore requires an expression. But you have define-coroutine, who's elaboration is a define form. So rather than using begin, you can use a let to turn it into an expression, giving you something like this:
(register-message-handler
msg-type
(let ()
(define-coroutine (handler-accessor) ....)
handler-accessor))
1Bad design decision...I know. Water under the bridge from many decades back. :(
There are two very useful functions in SLIME: slime-copy-or-inspect-presentation-at-mouse and slime-presentation-menu. But they must be called with an event argument. In order to generate an even I'd need to do a lot of logistics (calculating the region occupied by a printed representation of the object the "mouse" is currently pointing at, lines and columns - something I don't really want to do because, certainly there's something in Emacs that calculates all that stuff already.
So, is there an easy way to generate "fake" mouse event? Because using mouse for only two things in an editor that otherwise doesn't require mouse feels... well, not very smart. :)
EDIT
Here's what I've tried:
(define-key lisp-mode-map (kbd "C-x ?")
#'(lambda ()
(interactive)
(message "called")
(slime-copy-or-inspect-presentation-at-mouse
`(mouse-2 ;; button
(,(selected-window) ;; window
,(point) ;; position
(0 . 0) ;; window-relative pixel
0 ;; timestamp
nil ;; object
,(point) ;; text position
(,(current-column) . ;; column
,(line-number-at-pos (point))) ;; line
nil ;; image
(0 . 0) ;; object-relative pixel
(1 . 1))))))
(define-key lisp-mode-map (kbd "C-x SPC")
#'(lambda ()
(interactive)
(message "called")
(slime-presentation-menu
`(mouse-3 ;; button
(,(selected-window) ;; window
,(point) ;; position
(0 . 0) ;; window-relative pixel
0 ;; timestamp
nil ;; object
,(point) ;; text position
(,(current-column) . ;; column
,(line-number-at-pos (point))) ;; line
nil ;; image
(0 . 0) ;; object-relative pixel
(1 . 1))))))
And this actually can get me to the point where it displays menu, but when slime-presentation-menu calls any of the functions bound to menu items they somehow see that they weren't called with a "real" mouse event, throw and exit. :(
EDIT2
I actually think this is because of the x-popup-menu, which dispatches different events when you select a menu item with mouse or with keyboard... arrrrrgh.
Commands that expect to be bound to a mouse click take an event parameter. This is a list full of stuff like the button clicked, the position, the window, etc. See 21.7.4 Click Events in the Elisp manual.
Here's a simple example to fake a scroll wheel event:
(mwheel-scroll `(mouse-5 ;; button
(,(selected-window) ;; window
,(point) ;; position
(0 . 0) ;; window-relative pixel
0 ;; timestamp
nil ;; object
,(point) ;; text position
(,(current-column) . ;; column
,(line-number-at-pos (point))) ;; line
nil ;; image
(0 . 0) ;; object-relative pixel
(1 . 1)))) ;; object size
Here's an example of a real event:
'(mouse-4
(#<window 374 on *scratch*>
120
(6 . 10)
1301935153
nil
120
(0 . 0)
nil
(6 . 10)
(7 . 15)))
posn-at-point does almost the right thing. Here's a way to compare its output to a real mouse event:
(defun my/test-posn (e)
(interactive "e")
(message "%S\n%S" e `(down-mouse-3 ,(posn-at-point))))
(global-set-key [down-mouse-3] #'my/test-posn)
Output:
(down-mouse-3 (#<window 73 on blah> 3152 (0 . 594) 145393072 nil 3152 (0 . 33) nil (1 . 4) (8 . 18)))
(down-mouse-3 (#<window 73 on blah> 3152 (0 . 594) 0 nil 3152 (0 . 33) nil (0 . 0) (8 . 18)))
I have the following dumb test code:
#lang racket
(define vars '('g1 'g2 'g3 'g1))
(define addrs '(123 456 789 012))
(define immhs (make-immutable-hasheq empty))
(define immhs* (for/fold ([imhs immhs]) ([var (in-list vars)] [addr (in-list addrs) ]) (hash-set imhs var addr )))
immhs*
(hash-ref immhs* 'g1)
The output is:
'#hasheq(('g1 . 123) ('g2 . 456) ('g3 . 789) ('g1 . 12))
hash-ref: no value found for key: 'g1
Why can't the hash-ref reference to the 'g1? (it will also fail on 'g2, etc)
Then I uses (hash-keys immhs*), it returns '('g1 'g2 'g3 'g1), where there is 'g1;
and I use further (car (hash-keys immhs*)), it returns ''g1 ; then the question is that why there are two quote ' before?
The problem is exactly the two quotes that you see: x evaluates to whatever x is bound to, 'x evaluates to a symbol, and ''x evaluates to a quoted form -- 'x. Try this:
(define vars '(g1 g2 g3 g1))
and it will work.