guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to use guile in a development process


From: Adriano Peluso
Subject: Re: How to use guile in a development process
Date: Thu, 29 Apr 2021 10:16:03 +0200

Il giorno gio, 29/04/2021 alle 10.35 +1000, Anthony Quizon ha scritto:
> Hello,
> 
> I'm having trouble finding a good development process with guile.
> 
> I have a file foo.scm and I'm trying to load it into the repl.
> However, I couldn't find any documentation on how to easily do this.
> I tried looking up ",help module" in the repl which told me to use
> ",load
> FILE".
> But when I tried this I got the error "In procedure primitive-load-
> path:
> Unable to find file "system/repl/foo.scm" in load path"
> 
> I don't know where to look to change my load file for the repl.
> 
> I read in a forum somewhere to add (add-to-load-path ".") in my .guile
> file
> but that didn't work.
> 
> How do I load a file from the current path that I'm in?

at the Guile REPL, you can issue:

scheme@(guile-user)> (load "path/to/your/file.scm")

The path/to/your/file.scm is relative to some position in the file
system

Which one ?

You can know that with 

scheme@(guile-user)> (getcwd)

So, say, for example, that getcwd returns some path

scheme@(guile-user)> (getcwd)
$1 = "/home/anthony"


and say that you project is in 

/home/anthony/projects/guile-musings/


In order to load your file, tou need to issue

scheme@(guile-user)> (load "projects/gule-musings/foo.scm")


That will compile your file and store the compiled file in some
position buried in your home folder

In this way, when you'll load the file again it won't be recompiled,
unless it has changed

Now, having to write a long path can be annoying, can't it ?

If you have the so called "read-line" thing activated, you can use the
up arrow on your keyboard to scroll up the lines that you issied
previoulsy, so you won't have to type the path again

In a file named ".guile" in your home folder, paste these 2 lines

(use-modules (ice-9 readline))
(activate-readline)


then launch Guile again

This will give you the read-line thing

I suggest you to add 2 more lines to your .guile file

(use-modules (ice-9 pretty-print))

(use-modules (texinfo reflection))

this will give you a slighlty less frustrating experience but I won't
go into that now, this post would be too long

So now there are 2 more things you can consider to lessen the burden of
having to load a file every time

1) you can cd to the folder containing your project BEFORE launching
Guile

So in this Guile session, getcwd will return the path to you project
and so (load "foo.scm") will be enough, no long paths

2) At the Guile REPL you can issue (assuming you started Guile in your
home folder)

scheme@(guile-user)> (chdir "projects/guile-musings")

This will change what getcwd returns, as you can guess

scheme@(guile-user)> (getcwd)
$1 = "/home/anthony/projects/guile-musings"

So now you can just
scheme@(guile-user)> (load "foo.scm")

I hope this helps

> But more importantly, what is the typical workflow when using guile?
> Do people write files to the filesystem and load them in the repl to
> try it
> out?

Eh, this is a whole different question

Honestly, I'm a bit confused about this myself, after so many years of
fighting with Guile

So there are several levels of interaction with Guile

you can keep 2 windows opened, one with a Guile REPL where you can try
out things nad onother one with a Guile source file

You can load the file in the REPL and then continue trying out things
using stuff that was defined in the file

this is level 1

With some more setup and machinery, you can have unit tests available
in the terminal and maybe even in the REPL (I'm not sure)

So you can write little bits and test then out as soon as you want

There's a Guiler (Jecko) who wrote a series of blog posts about using
extensively unit testing to develop e Guile things

Another possibility is an Emacs module called Geiser

Geiser provides some sort of an IDE for Guile, based on Emacs

With IDE I mean you can have things like autocompletion (if you can
deal with the Emacs packages quagmire) and jump to definition and
interactively consult the documentation for a procedure

Another possibility is a project called Guile Studio

Guile Studio is also based on Emacs but it aims to mimick Racket's
DrRacket, where you have 2 panes, in one you have a REPL and issu code
bits at it, in another you have a sort of a canvas where you can see
the results of evaluating your code

It also has some sort of pictures language, with which you can
manipulate 2D drawings with in scheme

But it's at a very early stage, so I don't know how usable it is
actually 

There are 2 things that can be frustrating that I want to suggest you 

1) Guile stores some information about your source code in compiled
files so error messages can be slightly more accurate/informative when
using compiled files

If you are issuing bits of code at the REPL the error messages could be
less helpful

2) the debugger doen't work yet. It can do some things but not all
you'd expect from something called "debugger" (as far as I understand)

So people actually use a procedure called "pk"

pk prints its argument to the REPL (so you can see what it is) and
returns it as it is

So say you want to see what some variable buried deep in your code is,
you can wrap it in a call to pk like this

(some-procedure (pk my-thing))

some-procedure will receive your thing but you'll also see it printed

I hope this helps too





reply via email to

[Prev in Thread] Current Thread [Next in Thread]