This article is outdated, the flow described here has been replaced by Vip. Please see related articles for more into.

The Flow

The basics of using vim within the PicoLisp interpreter. See also the article Using 'edit'.

Using 'vi' and 'ld'

at the command line,

   $ echo "(de foo ())" > foo.l

This command put a function prototype in the file foo.l.

Now fire up PicoLisp in Debug Mode with that file loaded,

   $ pil foo.l +
   :



Let's edit our favorite function!

   : (vi 'foo)

We're are now looking at the definition of foo within a Vim Buffer within a running PicoLisp instance. Wow! To verify that this is indeed the truth, and nothing but the truth, we better :quit Vim.

   :

PicoLisp was patiently waiting for us the whole time.

Back to fooling around in Vim.

   : (vi 'foo)



Let's change foo so that it prints a cute little ASCII mouse.

   (de foo ()
      (println "A_A")
      (println "o o")
      (println ">v<") )

Satified with our new definition of foo, we exit insert mode and type ZZ in command mode, to save our changes and return to PicoLisp.

Back at the REPL now, we need to reload `foo` so we can play with the new version of it.

   : (ld)
   # foo redefined
   -> foo
   :



What happened there? As always, when you're not sure what a new function does... (doc 'ld). Ah, gotcha.

Sweet! Now let's test it out.

   : (foo)
   "A A"
   "o o"
   ">v<"
   -> ">v<"

That's pretty cool, but I don't like all the double-quotes in the output. Let's change that.

: (vi 'foo)



We need to substitute all the println's to prinl's in our definition. We can do this in one Vim command, :%s/println/prinl. Enter that now. Magically, all the println's have changed to prinl's! That was slick. Read this to find out what that command just did.

Our lastest foo should now be

   (de foo ()
      (prinl "A_A")
      (prinl "o o")
      (prinl ">v<") )



Exit Vim with ZZ and ld the file.


   : (ld)
# foo redefined
   -> foo
   :



Remember the difference between println and prinl? If not, now would be the time to (doc 'println) and (doc 'prinl).

Try it out!

   : (foo)
   A A
   o o
   >v<
   -> ">v<"

Neato!

But I'm still not sold on the function's return value. A bit offputting to see an additional nose/whisker combo just floating there in mid air. Foo! Ideally foo would simply return T to let us know that a cute little ASCII mouse has been printed. Luckily, there's a function for that!

: (doc 't)

The example is the same use case as ours! This is gonna be perfect.

Back to the foo...ture.

: (vi 'foo)



Change foo to look like this,

   (de foo ()
      (t (prinl "A A")
         (prinl "o o")
         (prinl ">v<") ) )

In command mode, save and quit with ZZ.

ld the file and try it out again.

   : (ld)
# foo redefined
   -> foo
   : (foo)
   A A
   o o
   >v<
   -> T
   :



Our little mouse friend is getting suspicious of all the editing...

: (vi 'foo)

Let's change him one last time.

   (de foo ()
      (t (prinl "A A")
         (prinl "_ /")
         (prinl "o O")
         (prinl ">v<") ) )

Save and quit, reload and fire away.

   : (ld)
# foo redefined
   -> foo
   : (foo)
   A A
   _ /
   o O
   >v<
   -> T



Are you feeling the flow? Simply call vi and then ld!

https://picolisp.com/wiki/?editingflow

23jun23    pablo_escoberg
Revision History