guile-devel
[Top][All Lists]
Advanced

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

Re: Proposal for a new (ice-9 history)


From: Mark H Weaver
Subject: Re: Proposal for a new (ice-9 history)
Date: Mon, 29 Oct 2018 19:54:14 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

Hi Mikael,

Mikael Djurfeldt <address@hidden> writes:

> I'd like to rewrite (ice-9 history) to conform to the full GDB value
> history syntax. This is because I find that I miss being able to refer
> to "the last value" etc.

Yes, I've also missed this!

> Currently we have:
>
> $<N> the N:th value from the start
>
> The extension would add bindings for:
>
> $$<N> the N:th value from the end
>
> $ the last value (= $$0)
>
> $$ the value just prior to the last value (= $$1)
>
> Implementation:
>
> Currently, every step in the REPL defines a $<N> in the module
> (value-history) the interface of which is appended to the list of used
> interfaces for the (current-module).
>
> The new implementation would just add a new result value to a list,
> not doing any definition.
>
> The interface of (value-history) would instead have a lazy-binder
> which provides a syntax transformer for every $... actually being
> used. The $... identifier would expand into a list-ref into the value
> history.
>
> Please evaluate this suggestion and give comments or an OK.

This strategy sounds good to me.  I'd also like to hear what Andy and
Ludovic think.

However, there's a complication with using '$' in this way.  '$' is
already widely used as part of the syntax for (ice-9 match), to specify
patterns that match record objects.  More precisely, it is a literal
identifier recognized by 'match' and related macros, in the same sense
that 'else' and '=>' are literal identifiers recognized by the 'cond'
macro.

R5RS section 4.3.2 (Pattern language) specifies how these literal
identifiers are to be compared with identifiers found in each macro use:

     Identifiers that appear in <literals> are interpreted as literal
     identifiers to be matched against corresponding subforms of the
     input.  A subform in the input matches a literal identifier if and
     only if it is an identifier and either both its occurrence in the
     macro expression and its occurrence in the macro definition have
     the same lexical binding, or the two identifiers are equal and both
     have no lexical binding.

The implication is that these literal identifiers such as 'else', '=>'
and '$' lose their special meaning in any environment where they are
bound, unless the same binding is visible in the corresponding macro
definition environment.  R6RS and R7RS also specify this behavior.

For example:

--8<---------------cut here---------------start------------->8---
address@hidden ~$ guile
GNU Guile 2.2.3
Copyright (C) 1995-2017 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> ,use (ice-9 match)
scheme@(guile-user)> ,use (srfi srfi-9)
scheme@(guile-user)> (define-record-type <foo> (make-foo a b) foo? (a foo-a) (b 
foo-b))
scheme@(guile-user)> (match (make-foo 1 2) (($ <foo> a b) (+ a b)))
$1 = 3
scheme@(guile-user)> (define $ 'blah)
scheme@(guile-user)> (match (make-foo 1 2) (($ <foo> a b) (+ a b)))
<unnamed port>:6:0: Throw to key `match-error' with args `("match" "no matching 
pattern" #<<foo> a: 1 b: 2>)'.

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]>
--8<---------------cut here---------------end--------------->8---

To avoid colliding with the popular 'match' syntax, how about making
'$$' the last value ($$0), and omitting the alias for '$$1'?

What do you think?

    Regards,
      Mark



reply via email to

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