Re: GOOPS question

2021-04-30 Thread Mikael Djurfeldt
Hi!

I attach a template which you could build on. Please post your class when
you're done. :)

Best regards,
Mikael

On Fri, Apr 30, 2021 at 1:11 AM Damien Mattei 
wrote:

> hi,
> i want to create a growable vector class in Guile,
> such as std::vector or python list,
> first i do not know if it exist already? seems not
>
> i want to use GOOPS but i do not understand how the superclass could be
> accessed,used, instanciate...
> for example in the doc there is:
> (define-class  () r i #:name "Complex")
>
> seems  superclass is of no use
>
> for my growable vector i would like to use array as superclass?
> but perhaps should it be just a slot as array are a subset of growable
> array ,so a subclass
>
> anyway if i write something ike that:
> (define-class  () .
> how can i use the  object?
>
> i think perhaps i should not define a superclass or  as super
> class
> any advice welcome...
>
> Damien
>
(define-module (oop gvector)
  #:use-module (oop goops)
  #:use-module ((guile)
		#:select (vector-length vector-ref vector-set!)
		#:prefix orig:)
  #:export ()
  #:replace (vector-length vector-ref vector-set!))

;;; Constants

(define *initial-allocated-size* 8)

;;; Capture original bindings of vector getters and setters

(define-generic vector-length)

(define-method (vector-length (v ))
  (orig:vector-length v))

(define-generic vector-set!)

(define-method (vector-set! (gv ) (i ) obj)
  (orig:vector-set! gv i obj))

(define-generic vector-ref)

(define-method (vector-ref (gv ) (i ))
  (orig:vector-ref gv i))

;;; The  class

(define-class  ()
  (v #:init-value (make-vector *initial-allocated-size*) #:getter v)
  (length #:init-value 0 #:getter vector-length))

(define (assert-size! gv i)
  (if (>= i (length gv))
  *unspecified*)) ; do nothing for now

(define-method (vector-set! (gv ) (i ) obj)
  (assert-size! gv i)
  (vector-set! (v gv) i obj))

(define-method (vector-ref (gv ) (i ))
  (assert-size! gv i)
  (vector-ref (v gv) i))


Re: GOOPS question

2021-04-30 Thread Linus Björnstam
This does not answer your question, but:

There was just a SRFI released for growable vectors. I don't know about any 
interest to have it included in guile, but the reference implentation is 
probably trivially portable: https://srfi.schemers.org/srfi-214/srfi-214.html



-- 
  Linus Björnstam

On Fri, 30 Apr 2021, at 01:10, Damien Mattei wrote:
> hi,
> i want to create a growable vector class in Guile,
> such as std::vector or python list,
> first i do not know if it exist already? seems not
> 
> i want to use GOOPS but i do not understand how the superclass could be
> accessed,used, instanciate...
> for example in the doc there is:
> (define-class  () r i #:name "Complex")
> 
> seems  superclass is of no use
> 
> for my growable vector i would like to use array as superclass?
> but perhaps should it be just a slot as array are a subset of growable
> array ,so a subclass
> 
> anyway if i write something ike that:
> (define-class  () .
> how can i use the  object?
> 
> i think perhaps i should not define a superclass or  as super
> class
> any advice welcome...
> 
> Damien
> 



Re: GOOPS question

2021-04-30 Thread Damien Mattei
thank for your answer but my question was just about use of superclass
SRFI implementation is too complex  for what i want to do now,
template is 1 dimension gvector, that's neolithic for me :-) and do not
explain use of superclass...
Damien

On Fri, Apr 30, 2021 at 9:57 AM Linus Björnstam 
wrote:

> This does not answer your question, but:
>
> There was just a SRFI released for growable vectors. I don't know about
> any interest to have it included in guile, but the reference implentation
> is probably trivially portable:
> https://srfi.schemers.org/srfi-214/srfi-214.html
>
>
>
> --
>   Linus Björnstam
>
> On Fri, 30 Apr 2021, at 01:10, Damien Mattei wrote:
> > hi,
> > i want to create a growable vector class in Guile,
> > such as std::vector or python list,
> > first i do not know if it exist already? seems not
> >
> > i want to use GOOPS but i do not understand how the superclass could be
> > accessed,used, instanciate...
> > for example in the doc there is:
> > (define-class  () r i #:name "Complex")
> >
> > seems  superclass is of no use
> >
> > for my growable vector i would like to use array as superclass?
> > but perhaps should it be just a slot as array are a subset of growable
> > array ,so a subclass
> >
> > anyway if i write something ike that:
> > (define-class  () .
> > how can i use the  object?
> >
> > i think perhaps i should not define a superclass or  as super
> > class
> > any advice welcome...
> >
> > Damien
> >
>


Re: GOOPS question

2021-04-30 Thread Mikael Djurfeldt
The superclass question is a matter of taste.

First note that in CLOS-like objects systems, such as GOOPS, methods are
not components of classes but it is rather the set of operations =
generics/methods around a type which define its behavior. Roughly speaking,
the only things directly tied to the class are the slots. In this regard
 is opaque---there are no accessible slots. Therefore, if using it
as a superclass, it won't add any slots to your instances apart and above
what you explicitly add in your class definition. So, you should think of
the role of  as a superclass more in terms of natural grouping, and
its role in selecting methods when you operate on the object using
generics, than anything else. The *only* functional effect of using 
as a superclass in this case is that methods taking an  argument
will also accept instances of  as an argument. (This does not
apply to *functions* now taking array as an argument.)

I would say that you could choose between having no explicit superclass and
having  as superclass. In your case there would not be any big
functional difference.

If you, in your last answer, by "template" refer to my answer, then you are
of course free to replace all  stuff with the corresponding 
stuff.

In my example, I chose to use  as superclass because I regarded
 to be a specialization. It is true that  logically could
be regarded as a specialization of , but you can't do anything
about that.

Best regards,
Mikael

On Fri, Apr 30, 2021 at 11:48 AM Damien Mattei 
wrote:

> thank for your answer but my question was just about use of superclass
> SRFI implementation is too complex  for what i want to do now,
> template is 1 dimension gvector, that's neolithic for me :-) and do not
> explain use of superclass...
> Damien
>
> On Fri, Apr 30, 2021 at 9:57 AM Linus Björnstam <
> linus.inter...@fastmail.se>
> wrote:
>
> > This does not answer your question, but:
> >
> > There was just a SRFI released for growable vectors. I don't know about
> > any interest to have it included in guile, but the reference implentation
> > is probably trivially portable:
> > https://srfi.schemers.org/srfi-214/srfi-214.html
> >
> >
> >
> > --
> >   Linus Björnstam
> >
> > On Fri, 30 Apr 2021, at 01:10, Damien Mattei wrote:
> > > hi,
> > > i want to create a growable vector class in Guile,
> > > such as std::vector or python list,
> > > first i do not know if it exist already? seems not
> > >
> > > i want to use GOOPS but i do not understand how the superclass could be
> > > accessed,used, instanciate...
> > > for example in the doc there is:
> > > (define-class  () r i #:name "Complex")
> > >
> > > seems  superclass is of no use
> > >
> > > for my growable vector i would like to use array as superclass?
> > > but perhaps should it be just a slot as array are a subset of growable
> > > array ,so a subclass
> > >
> > > anyway if i write something ike that:
> > > (define-class  () .
> > > how can i use the  object?
> > >
> > > i think perhaps i should not define a superclass or  as super
> > > class
> > > any advice welcome...
> > >
> > > Damien
> > >
> >
>


Re: GOOPS question

2021-04-30 Thread Mikael Djurfeldt
On Fri, Apr 30, 2021 at 1:11 AM Damien Mattei 
wrote:

> for example in the doc there is:
> (define-class  () r i #:name "Complex")
>
> seems  superclass is of no use
>

Well, it certainly *is* of use in the sense that methods operating on
 will immediately start to also accept  as an argument.
That might seem worrisome but is not if there is some agreement on which
operations should be implemented for all numbers. So, if you had previously
written an algorithm which operates on numbers, there's now a good chance
that it would also work for  objects.


Re: How to use guile in a development process

2021-04-30 Thread Leo Butler
Tim Meehan  writes:

>>
>> How do I load a file from the current path that I'm in?
>> 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?
>> Or is there a faster way to do things?

I use geiser in emacs to run a guile repl and edit source code. This
allows one to write source in a file and compile/load it, or write the
source in the repl and copy it into a file when it is working and either
way works fine.

Leo



Re: Python's pdb module

2021-04-30 Thread Ricardo G. Herdt

Hi Tim,

Am 30.04.2021 05:26 schrieb Tim Meehan:

Is there something in Guile that is similar to Python's "pdb" module?
For instance, sometimes I find it helpful to pause right before 
something

bad happens with:


you can use the debugging features of the REPL. See:
,help debug

Example:
,break some-function-that-is-going-to-fail-miserably

Related to ,break is ,break-at-source, where you can give the line 
number where you want to stop.


You may also find ",trace" useful, it shows all calls to a given 
function.


Best,

Ricardo



Re: Python's pdb module

2021-04-30 Thread Matt Wette



On 4/29/21 8:26 PM, Tim Meehan wrote:

Is there something in Guile that is similar to Python's "pdb" module?
For instance, sometimes I find it helpful to pause right before something
bad happens with:

#!/usr/bin/env python3
import pdb; pdb.set_trace()
some_function_that_is_going_to_fail_miserably()


I started on something years ago but never got it working as nice as python,
as the guile debugger still needs some help to get there.   Try this 
snippet.


(define-syntax-rule (jump-to-debugger)
  (if (eqv? 'regular (vm-engine))
  (give-warning)
  (start-repl
   #:debug (make-debug (stack->vector (make-stack #t)) 0 "trap!" #t

You'll need some of this mess to resolve procedures:

(use-modules (system repl repl))
(use-modules (system repl debug))
(use-modules (system repl common))
(use-modules (system repl command))
(use-modules (system vm frame))
(use-modules (system vm vm))
(use-modules (ice-9 control))
(use-modules (ice-9 rdelim))
(use-modules (ice-9 pretty-print))
(use-modules (system base compile))

Matt




Re: GOOPS question

2021-04-30 Thread Stefan Israelsson Tampe
If performance is important, a goops solution can be slow in vector-ref and
vector-set! operations due
to two reasons. (I have pounder an implementation of resizable python lists
and here is my tips),

1. slot-ref/slot-set! is slow (I try to fix this using the much more
difficult struct-ref/struct-set!)
2. generic-method-dispatch is slow, I try to make a wrapper function in
which we short cut for
python/sheme internal types and if they do not match use the generic method.


On Fri, Apr 30, 2021 at 1:57 PM Mikael Djurfeldt 
wrote:

> On Fri, Apr 30, 2021 at 1:11 AM Damien Mattei 
> wrote:
>
> > for example in the doc there is:
> > (define-class  () r i #:name "Complex")
> >
> > seems  superclass is of no use
> >
>
> Well, it certainly *is* of use in the sense that methods operating on
>  will immediately start to also accept  as an argument.
> That might seem worrisome but is not if there is some agreement on which
> operations should be implemented for all numbers. So, if you had previously
> written an algorithm which operates on numbers, there's now a good chance
> that it would also work for  objects.
>


Re: GOOPS question

2021-04-30 Thread Mikael Djurfeldt
Generic method dispatch is *supposed* to be fast. It was fast once upon a
time. We should fix that.

On Fri, Apr 30, 2021 at 2:19 PM Stefan Israelsson Tampe <
stefan.ita...@gmail.com> wrote:

> If performance is important, a goops solution can be slow in vector-ref
> and vector-set! operations due
> to two reasons. (I have pounder an implementation of resizable python
> lists and here is my tips),
>
> 1. slot-ref/slot-set! is slow (I try to fix this using the much more
> difficult struct-ref/struct-set!)
> 2. generic-method-dispatch is slow, I try to make a wrapper function in
> which we short cut for
> python/sheme internal types and if they do not match use the
> generic method.
>
>
> On Fri, Apr 30, 2021 at 1:57 PM Mikael Djurfeldt 
> wrote:
>
>> On Fri, Apr 30, 2021 at 1:11 AM Damien Mattei 
>> wrote:
>>
>> > for example in the doc there is:
>> > (define-class  () r i #:name "Complex")
>> >
>> > seems  superclass is of no use
>> >
>>
>> Well, it certainly *is* of use in the sense that methods operating on
>>  will immediately start to also accept  as an
>> argument.
>> That might seem worrisome but is not if there is some agreement on which
>> operations should be implemented for all numbers. So, if you had
>> previously
>> written an algorithm which operates on numbers, there's now a good chance
>> that it would also work for  objects.
>>
>


Re: GOOPS question

2021-04-30 Thread Mikael Djurfeldt
Preferably, the dispatch should be done as much as possible during compile
time such that it takes zero time during runtime.

On Fri, Apr 30, 2021 at 4:50 PM Mikael Djurfeldt 
wrote:

> Generic method dispatch is *supposed* to be fast. It was fast once upon a
> time. We should fix that.
>
> On Fri, Apr 30, 2021 at 2:19 PM Stefan Israelsson Tampe <
> stefan.ita...@gmail.com> wrote:
>
>> If performance is important, a goops solution can be slow in vector-ref
>> and vector-set! operations due
>> to two reasons. (I have pounder an implementation of resizable python
>> lists and here is my tips),
>>
>> 1. slot-ref/slot-set! is slow (I try to fix this using the much more
>> difficult struct-ref/struct-set!)
>> 2. generic-method-dispatch is slow, I try to make a wrapper function in
>> which we short cut for
>> python/sheme internal types and if they do not match use the
>> generic method.
>>
>>
>> On Fri, Apr 30, 2021 at 1:57 PM Mikael Djurfeldt 
>> wrote:
>>
>>> On Fri, Apr 30, 2021 at 1:11 AM Damien Mattei 
>>> wrote:
>>>
>>> > for example in the doc there is:
>>> > (define-class  () r i #:name "Complex")
>>> >
>>> > seems  superclass is of no use
>>> >
>>>
>>> Well, it certainly *is* of use in the sense that methods operating on
>>>  will immediately start to also accept  as an
>>> argument.
>>> That might seem worrisome but is not if there is some agreement on which
>>> operations should be implemented for all numbers. So, if you had
>>> previously
>>> written an algorithm which operates on numbers, there's now a good chance
>>> that it would also work for  objects.
>>>
>>


Re: Python's pdb module

2021-04-30 Thread Tim Meehan
Thanks for the ideas folks!

> On Apr 30, 2021, at 08:24, Matt Wette  wrote:
> 
> 
>> On 4/29/21 8:26 PM, Tim Meehan wrote:
>> Is there something in Guile that is similar to Python's "pdb" module?
>> For instance, sometimes I find it helpful to pause right before something
>> bad happens with:
>> 
>> #!/usr/bin/env python3
>> import pdb; pdb.set_trace()
>> some_function_that_is_going_to_fail_miserably()
> 
> I started on something years ago but never got it working as nice as python,
> as the guile debugger still needs some help to get there.   Try this snippet.
> 
> (define-syntax-rule (jump-to-debugger)
>   (if (eqv? 'regular (vm-engine))
>   (give-warning)
>   (start-repl
>#:debug (make-debug (stack->vector (make-stack #t)) 0 "trap!" #t
> 
> You'll need some of this mess to resolve procedures:
> 
> (use-modules (system repl repl))
> (use-modules (system repl debug))
> (use-modules (system repl common))
> (use-modules (system repl command))
> (use-modules (system vm frame))
> (use-modules (system vm vm))
> (use-modules (ice-9 control))
> (use-modules (ice-9 rdelim))
> (use-modules (ice-9 pretty-print))
> (use-modules (system base compile))
> 
> Matt
> 
>