Russell McManus | 4 Oct 17:25 2004
Picon

how to handle "adress already in use" after calling comm:start-up-server?


I am creating tcp servers using comm:start-up-server.  But sometimes
when I specify a port that is in use, a condition is signalled in the
thread context of the server.

How can I handle this condition, and retry on another port?  I know
how to do this when I start up another thread with
mp:process-run-function, but comm:start-up-server starts up a thread
internally, so I'm not sure how to proceed.

Thanks for any ideas...

-russ

lisptracker | 4 Oct 19:20 2004
Picon

Passing primitive value by reference

Hi
 
One my frind, who likes C++ much, asked me How to pass by reference value of primitive type to function. It's common technique in C/C++ to share one memory cell between multiple functions passing address of cell as value. One way similar to it is to pass value wraped into cons cell. Another way is to use dynamic extent or macro, but it is very ugly.
 
As far as I know a primitive value being passed to a function, remains unmuttable object. So I have to use some wrapper...
To answer a question I should find some way to do it like below:
 
(let ((mutable-var 2))
    (function-to-change-var mutable-var)
mutable-var)
 
So mutable-var is not equals 2 after calling of function-to-change-var.
 
Thanks in advance
Lisper
Pascal Costanza | 4 Oct 19:45 2004
Picon

Another MOP bug...

...but a minor one. The MOP spec states that the :default-initargs in a 
defclass form are passed as :direct-default-initargs to the 
corresponding call of ensure-class (and passed on to 
ensure-class-using-class and initialize-instance). LispWorks passes them 
as :default-initargs.

(The requirement to convert them to :direct-default-initargs seems 
somewhat gratuitous, but that's how it is specified.)

This deviation should at least be documented.

All the best,
Pascal

--

-- 
Pascal Costanza               University of Bonn
mailto:costanza <at> web.de        Institute of Computer Science III
http://www.pascalcostanza.de  Römerstr. 164, D-53117 Bonn (Germany)

Mark Nahabedian | 4 Oct 19:57 2004
Picon

Re: Passing primitive value by reference

On Mon, Oct 04, 2004, 13:20, lisptracker <lisptracker <at> mail.ru> wrote
>Hi
>
>One my frind, who likes C++ much, asked me How to pass by reference value 
of primitive type to function. It's common technique in C/C++ to share one 
memory cell between multiple functions passing address of cell as value. One 
way similar to it is to pass value wraped into cons cell. Another way is to 
use dynamic extent or macro, but it is very ugly.
>
>As far as I know a primitive value being passed to a function, remains 
unmuttable object. So I have to use some wrapper...
>To answer a question I should find some way to do it like below:
>
>(let ((mutable-var 2))
>    (function-to-change-var mutable-var)
>mutable-var)
>
>So mutable-var is not equals 2 after calling of function-to-change-var.

Why would you want to do this in Lisp?  WHat are you really trying to do?
I ask because though C and C++ programers frequently need to pass "by 
reference" parameters, I as a Lisp programmer don't recall ever having to do 
so.

The typical use for by-reference parameters in C and C++ is for a function 
to return more than one value, e.g. returning a sucess/failure code as the 
value of the function and filling in some structure which was passed by 
reference.  The way one would do this in Lisp is to have the function return 
multiple values.  In Lisp, functions can return more than one value.  In
C and C++ they can't.

If you really need to be able to have some function modify a value that it 
doesn;t have access to, you can always pass a closure which modifies the 
value, e.g.:

for some code fragment 

   ...
   (let ((change-this-value 7))
     (some-function #'(lambda (new-value)
                        (setq change-this-value new-value)))
     ;; At this point the value of CHANGE-THIS-VALUE is 4
     )
   ...

which calls SOME-FUNCTION and expects it to modify the value of 
CHANGE-THIN-VALUE

(defun some-function (value-changer)
  (funcall value-changer 4))

tarvydas | 4 Oct 23:40 2004
Picon

Re: Passing primitive value by reference

On Monday 04 October 2004 01:20 pm, lisptracker wrote:
> As far as I know a primitive value being passed to a function, remains
> unmuttable object. So I have to use some wrapper... To answer a question I
> should find some way to do it like below:

Make sure that you are comparing apples with apples.

In C, you cannot do the following:

  &7

or

  &(3 + 4)

So, in C, you can't pass the address of a "primitive type", either!  

In C, when you do this:

  int x = 7;
  ...
  &x

You are creating a wrapper (it's name is "x"), putting the primitive value 7 
into it and then taking the address of the wrapper.

If you want to do *exactly* the same thing in lisp, you can use defstruct, 
make-array, cons, defclass and probably a bunch of other things that don't 
come to mind, to create the wrapper.

You can do *exactly* the same thing in Lispworks if you use the FLI, too.

You can play games with the :displaced-to option of make-array, to share 
memory.

But, of course, you're using Lisp so that you never again have to deal with 
the insanity of the baggage that C brings with it, right? :-)

You wouldn't solve the same problem the same way in Lisp as you do in C, 
because Lisp gives you better ways of solving the problem - ways that are 
much less error-prone (one of the points of using a better language!).  
Taking the address of a variable with a cheap built-in syntax is something 
you need to get rid of, so that you can have the much-more-important feature 
of garbage collection.

Sharing memory - without using the address operator - in Lisp is easy.  It 
happens all of the time, for example in lists (e.g. if x is a list, then (cdr 
x) shares memory with x).  C++-people tend to build list operators with 
*less* sharing and more wasted memory (e.g. cursors).

pt

lisptracker | 5 Oct 00:17 2004
Picon

Fw: Passing primitive value by reference


----- Original Message -----
From: "lisptracker" <lisptracker <at> mail.ru>
To: "Mark Nahabedian" <naha <at> MIT.EDU>
Sent: Tuesday, October 05, 2004 5:15 AM
Subject: Re: Passing primitive value by reference

> ----- Original Message -----
> From: "Mark Nahabedian" <naha <at> MIT.EDU>
> To: "lisptracker" <lisptracker <at> mail.ru>; <lisp-hug <at> xanalys.com>
> Sent: Tuesday, October 05, 2004 12:57 AM
> Subject: Re: Passing primitive value by reference
>
>
> > On Mon, Oct 04, 2004, 13:20, lisptracker <lisptracker <at> mail.ru> wrote
> > >Hi
> > >
> > >One my frind, who likes C++ much, asked me How to pass by reference
value
> > of primitive type to function. It's common technique in C/C++ to share
one
> > memory cell between multiple functions passing address of cell as value.
> One
> > way similar to it is to pass value wraped into cons cell. Another way is
> to
> > use dynamic extent or macro, but it is very ugly.
> > >
> > >As far as I know a primitive value being passed to a function, remains
> > unmuttable object. So I have to use some wrapper...
> > >To answer a question I should find some way to do it like below:
> > >
> > >(let ((mutable-var 2))
> > >    (function-to-change-var mutable-var)
> > >mutable-var)
> > >
> > >So mutable-var is not equals 2 after calling of function-to-change-var.
> >
> > Why would you want to do this in Lisp?  WHat are you really trying to
do?
> > I ask because though C and C++ programers frequently need to pass "by
> > reference" parameters, I as a Lisp programmer don't recall ever having
to
> do
> > so.
>
> He want pass reference to some "place" to many functions which can modify
> their arguments,
> so they can modify that place. He said it is way of sharing mutable value
> between multiple functions
> which were defined somewhere. I can do it with non primitive types easily,
> but for example numbers are immutable.
> Maybe best way is to wrap number to cons cell.
>
> He would thought that is impossible in Lisp. For some reasons I must prove
> him that thing is possible somehow and
> show most elegant way.
>
>
> > The typical use for by-reference parameters in C and C++ is for a
function
> > to return more than one value, e.g. returning a sucess/failure code as
the
> > value of the function and filling in some structure which was passed by
> > reference.  The way one would do this in Lisp is to have the function
> return
> > multiple values.  In Lisp, functions can return more than one value.  In
> > C and C++ they can't.
>
> I know. But looks like ability to return multiple values is not only one
> reason.
>
> For example at first we have closure:
>
> (let ((var 5))
>
>     (defun change-var-one ()
>         (setf var 6))
>
>     (defun change-var-two ()
>         (setf var (+ var 7)))
>
>     (defun change-var-three ()
>         (incf var)))
>
> Now we want to declare change-var-one, change-var-two, change-var-three in
> one place, declare var
> in another place and call these functions passing reference to place:
>
> (let ((place-one 5)
>        (place-two 5))
>
>     (change-var-one place-one)
>     (change-var-one place-two)
>     (change-var-two place-one)
>     (change-var-two place-two))
>
> More than that, he want to pass reference from outer world.
>
> (defun one-big-fun (reference-place)
>     (change-var-one reference-place)
>     (change-var-two reference-place)
> )
>
> > If you really need to be able to have some function modify a value that
it
> > doesn;t have access to, you can always pass a closure which modifies the
> > value, e.g.:
> >
> > for some code fragment
> >
> >    ...
> >    (let ((change-this-value 7))
> >      (some-function #'(lambda (new-value)
> >                         (setq change-this-value new-value)))
> >      ;; At this point the value of CHANGE-THIS-VALUE is 4
> >      )
> >    ...
> >
> > which calls SOME-FUNCTION and expects it to modify the value of
> > CHANGE-THIN-VALUE
> >
> > (defun some-function (value-changer)
> >   (funcall value-changer 4))
>
> Anyway, thank you, for your kind advice.
>
> Though it is another way to create a wrapper. Would it be efficient to
call
> function every time to change value ?
>
> Maybe there are some ways to do same thing with totaly different approach
> ?????
>
> So I repeat conditions and question:
>     1) There is some place where primitive value is stored
>     2) There are some functions which should modify places we point on, so
> we can share places between functions.
>
> How to share places between some functions and have ability to point place
> by name for that functions in most
> elegant way (is it closures, or macro, or dynamic vars ...) ?
>
> Best regards
> Lisper
>
>

lisptracker | 5 Oct 00:25 2004
Picon

Re: Passing primitive value by reference

----- Original Message -----
From: "tarvydas" <tarvydas <at> allstream.net>
To: "lisptracker" <lisptracker <at> mail.ru>; <lisp-hug <at> xanalys.com>
Sent: Tuesday, October 05, 2004 4:40 AM
Subject: Re: Passing primitive value by reference

> On Monday 04 October 2004 01:20 pm, lisptracker wrote:
> > As far as I know a primitive value being passed to a function, remains
> > unmuttable object. So I have to use some wrapper... To answer a question
I
> > should find some way to do it like below:
>
> Make sure that you are comparing apples with apples.
>
> In C, you cannot do the following:
>
>   &7
>
> or
>
>   &(3 + 4)
>
> So, in C, you can't pass the address of a "primitive type", either!
>
> In C, when you do this:
>
>   int x = 7;
>   ...
>   &x
>
> You are creating a wrapper (it's name is "x"), putting the primitive value
7
> into it and then taking the address of the wrapper.
>
> If you want to do *exactly* the same thing in lisp, you can use defstruct,
> make-array, cons, defclass and probably a bunch of other things that don't
> come to mind, to create the wrapper.
>
> You can do *exactly* the same thing in Lispworks if you use the FLI, too.
>
> You can play games with the :displaced-to option of make-array, to share
> memory.
>
> But, of course, you're using Lisp so that you never again have to deal
with
> the insanity of the baggage that C brings with it, right? :-)
>
> You wouldn't solve the same problem the same way in Lisp as you do in C,
> because Lisp gives you better ways of solving the problem - ways that are
> much less error-prone (one of the points of using a better language!).
> Taking the address of a variable with a cheap built-in syntax is something
> you need to get rid of, so that you can have the much-more-important
feature
> of garbage collection.

I think same. But people who likes C/C++ are often so inconvincible,
especially
if they can't do some things which they could in C++ easily. Looks like my
friend is one of them.

Regards
Lisper

Mikael Laurson | 5 Oct 20:04 2004
Picon

LWM and LWW

Hello,

We started to port our software from LWM to LWW. For the most part 
this work has advanced very well.
We have, however,  encountered some problems in LWW:

(1) in LWW we get  an error if we call 'apply' with a list who's 
length is greater than 255,
Is there a way to specify the length of the argument list for 'apply' 
(LWM seems to be
more tolerant when calling 'apply').

(2) whan a capi window is selected with a click in the window area, 
it receives extra events (click.-down,  click-motion, and 
click-release or for input-models: (:button-1  :press) (:button-1 
:motion) (:button-1  :release)).  In LWM the window is only selected. 
Is there a way to avoid these
extra events in LWW ?

Mikael

davef | 5 Oct 20:09 2004

Re: LWM and LWW


 > We started to port our software from LWM to LWW. For the most part 
 > this work has advanced very well.
 > We have, however,  encountered some problems in LWW:
 > 
 > 
 > (1) in LWW we get  an error if we call 'apply' with a list who's 
 > length is greater than 255,
 > Is there a way to specify the length of the argument list for 'apply' 

There's an upper bound given by the value of CALL-ARGUMENTS-LIMIT,
which you cannot change.

 > (LWM seems to be
 > more tolerant when calling 'apply').

Yes, but not by much. In LispWorks for Macintosh, CALL-ARGUMENTS-LIMIT
= 300. Perhaps you can modify your code to not pass so many arguments.

 > (2) whan a capi window is selected with a click in the window area, 
 > it receives extra events (click.-down,  click-motion, and 
 > click-release or for input-models: (:button-1  :press) (:button-1 
 > :motion) (:button-1  :release)).  In LWM the window is only selected. 
 > Is there a way to avoid these
 > extra events in LWW ?

I'm not sure what you mean by extra events. Do you have some example
code illustrating the issue?

--
Dave Fox			

Xanalys                 http://www.lispworks.com
Compass House
Vision Park, Chivers Way
Histon
Cambridge, CB4 9AD
England

lisptracker | 5 Oct 21:31 2004
Picon

Right way to mix things through FLI

Hi

I am writing application wich have to use C/C++ objects much. I wonder how
to organize C/C++ code for mixin Lisp and C/C++ calls in most elegant way,
especially for passing collections (like list) from internal C/C++ loops to Lisp. For
example, I have time critical C procedure which scans image and searches
conforming pair of points between two images, it puts pair in C++ linked
list when next pair is found. Of course I can pass Lisp function as
callback, but would it be effective to call that function many many times ?
I could also convert resulting C/C++ list to Lisp list, but then unnecessary
list memory issues are possible. The third solution is to incorporate
foreign list through FFI and walk on it's contents by (ffi:dereference...)
and so on. I can also use GC finalizers to free C/C++ objects when I do not
need them.

As Lisp performance is not enough for some tasks (LispWorks 4.3, WinXP).
There should be some way to do such things in right natural way.

I can do with my C/C++ libraries anything to adapt them to Lisp. What should
I do with code without much confrontation with C/C++ memory
allocation/deallocation issues and pass an results of fast internal loops in
most elegant way ?

Thanks in advance
Lisper


Gmane