Skip to content

Instantly share code, notes, and snippets.

@wesen
Created May 11, 2023 22:26
Show Gist options
  • Select an option

  • Save wesen/02b0cf9bafae67cae644fd01a620fa81 to your computer and use it in GitHub Desktop.

Select an option

Save wesen/02b0cf9bafae67cae644fd01a620fa81 to your computer and use it in GitHub Desktop.
#+begin_ai
[SYS]: You are a doom emacs and emacs lisp expert. You answer questions very concisely, aimed at expert users. You use modern libraries and a modern emacs lisp style.
[ME]: I want to practice structured editing with lispy, give me some exercises to practice functionality like "raise" and "move-up/move-down" and clone.
[AI]: Here are some exercises to practice lispy's "raise", "move-up/move-down", and "clone" functions:
1. Raise:
Given the form `(when (and (foo) (bar)) (baz))(cursor)`, `(cursor)` denotes the cursor position.
- Move the cursor to any position inside the `and` form.
- Press `r` to raise the form `(foo)`. The result should be `(when (foo) (baz))`.
- Undo the last operation and move the cursor inside the `(bar)` form.
- Press `r` again to raise `(bar)`. The result should be `(when (bar) (baz))`.
2. Move-up/move-down:
Given the form `(progn (foo) (noteq a b) (setq c 42))(cursor)`.
- Move the cursor inside the `(foo)` form
[ME]: Only give the start and the desired result, with a hint. Don't give the solution.
[AI]: 1. Raise:
Start: `(when (and (foo) (bar)) (baz))(cursor)`
Desired result: One of the following: `(when (foo) (baz))` or `(when (bar) (baz))`
Hint: Raise one of the `(foo)` or `(bar)` forms; place your cursor appropriately.
2. Move-up/move-down:
Start: `(progn (foo) (noteq a b) (setq c 42))(cursor)`
Desired result: `(progn (noteq a b) (setq c 42) (foo))`
Hint: Move the `(foo)` form down; place your cursor appropriately.
3. Clone:
Start: `(defun test (x) (lst x (list x)))(cursor)`
Desired result: `(defun test (x) (lst x (list x) (list x)))(cursor)`
Hint: Clone the `(list x)` form; place your cursor appropriately.
[ME]: Give a list of 10 exercises for the slurp and barf functions. Make them challenging.
[AI]: 1. Slurp:
Start: `(let ((x 1) (y 2)) (print (+ x y)) (cursor)(- x y))`
Desired result: `(let ((x 1) (y 2)) (print (+ x y) (- x y)))`
Hint: Slurp the `(- x y)` form into the `print` form.
2. Barf:
Start: `(when (and (or (foo) (bar) (baz(cursor))) (not (fizz))))`
Desired result: `(when (and (or (foo) (bar)) (not (fizz))) (baz(cursor)))`
Hint: Barf the `(baz)` form out of the `or` form.
3. Slurp and Barf:
Start: `(cond ((cursor)foo (bar-x)) ((baz-y) (zot-z)))`
Desired result: `(cond (foo (bar-x)) (baz-y (zot-z)))`
Hint: First slurp and then barf the `foo` form.
4. Multi-Slurp:
Start: `(when (foo) (barf-x) (bar(fn (print-x)) (print-y))(cursor))`
Desired result: `(when (foo) (barf-x) (bar (fn (print-x) (print-y))(cursor)))`
Hint: Slurp the two `print` forms into the `fn` form.
5. Multi-Barf:
Start: `(let ((x (+ 1 2 3(cursor)))))`
Desired result: `(let ((x (+ 1))) (- 2) (* 3))(cursor)`
Hint: Barf out the subtraction and multiplication forms.
6. Slurp and Raise:
Start: `(if (and (foo) (bar)) (cons (baz) (boo)))(cursor)`
Desired result: `(if (foo) (cons (and (baz) (boo)) (bar)))`
Hint: Slurp the `(baz)` form into the `and` form, then raise `(bar)`.
7. Slurp with nesting:
Start: `(progn (map 'nil (- x y) (cursor)lst1 lst2 lst3))`
Desired result: `(progn (map 'nil (- x y) lst1 lst2 lst3)(cursor))`
Hint: Slurp the three `lst` forms into the `map` form.
8. Multi-Slurp and Raise:
Start: `(cond ((and (foo) (or (bar) (baz(cursor)))) (print-x)))`
Desired result: `(cond ((foo) (print-x)) ((or (bar) (baz(cursor)))))`
Hint: Perform multiple slurp operations and then raise `(foo)`.
9. Slurp with concat:
Start: `(concat "foo" "bar" (cursor)"baz" "qux")`
Desired result: `(concat "foo" "bar" "baz" "qux")(cursor)`
Hint: Slurp the "baz" and "qux" strings into the `concat` form.
10. Barf out of a nested form:
Start: `(let ((x (list 1 2 3)) (y (vector(cursor)2 3 4))) (seq-difference x y))`
Desired result: `(let ((x (list 1 2 3)) (y 2 (vector(cursor)3 4))) (seq-difference x y))`
Hint: Barf the `2` out of the `vector` form.
[ME]:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment