erudite icon indicating copy to clipboard operation
erudite copied to clipboard

Can we capture a function output ?

Open vindarel opened this issue 6 years ago • 10 comments

Hi,

Is it possible (or the goal) in erudite to capture and print the output of a function, akin to org mode ?

I'm imagining:

#| The latest news are:

@capture
#|
(defun latest-news ()
  (…))
(latest-news)

Regards

vindarel avatar Sep 24 '19 09:09 vindarel

Nope :(

mmontone avatar Sep 24 '19 12:09 mmontone

This would cool to have. Add some special Erudite section tag, and connect to a Swank instance to evaluate the code and then print it.

mmontone avatar Mar 11 '20 00:03 mmontone

I've started to implement code evaluation.

It is incomplete and needs refinement at the moment, but I will work on it in the next days.

Look at the @eval section.

@vindarel

https://github.com/mmontone/erudite/commit/a4bd593df20395c496255b8af12dcebf57c987fa

mmontone avatar Mar 11 '20 13:03 mmontone

Hi,

Is it possible (or the goal) in erudite to capture and print the output of a function, akin to org mode ?

I'm imagining:

#| The latest news are:

@capture
#|
(defun latest-news ()
  (…))
(latest-news)

Regards

So, now, the answer to this question is, yes!

mmontone avatar Mar 11 '20 14:03 mmontone

TODO:

  • Implement a @local-eval tag that doesn't need to connect to a SWANK instance, and just evaluates code in the current Erudite image?
  • @code-and-eval tag, that prints code, and then prints the code evaluation result.
  • @code-and-local-eval ?
  • Add SWANK connection settings parameters to CLI and also ERUDITE function.
  • Improve evaluated code output format.

mmontone avatar Mar 11 '20 14:03 mmontone

That's great!

vindarel avatar Mar 12 '20 14:03 vindarel

Can you give the steps on how to setup this? By default, in the REPL, it didn't work. I tried setting erudite::*swank-port* to the current one, I tried creating a new swank server and telling erudite its port, but then the erudite:erudite command hangs. Do we have to set erudite::*swank-connection* manually? Thanks.

vindarel avatar Mar 15 '20 21:03 vindarel

You need to start a SWANK server with (SWANK:CREATE-SERVER :DONT-CLOSE T).

Please pull from this repo, as I've improved the error message.

Expect changes going forward; this is work in progress.

mmontone avatar Mar 15 '20 22:03 mmontone

OK got it. It was just a bad usage. I was trying this:

;; @eval
;; some comment
(+ 1 1)
;; @end eval

and the call to slime-eval was hanging,

where we need

;; @eval
;; (+ 1 1)
;; @end eval

or the same inside "#|".

vindarel avatar Mar 16 '20 12:03 vindarel

Ok. I wish it didn't hang, and signal an error instead. I'll look into that later.

mmontone avatar Mar 16 '20 13:03 mmontone