- Subject: Re: [slang-users] Can you do OO in Slang?
- From: "John E. Davis" <jed@xxxxxxxxxxx>
- Date: Thu, 28 Jan 2021 00:15:16 -0500
Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx> wrote:
> in one of the posts that announced a new libslang version I've noticed a
> syntax that seems to be an inheritance, i.e.:
>
> car = struct { name, price, max_velocity}
> truck = struct {@car, max_load};
>
> Now truck includes all the fields that car has. I wonder however if you can
> cast a truck at a car, to pass it to a generic car-related function? Is
> there casting in slang?
Yes, you can pass truck to a routine that expects a car as long as all
of the fields that the car function needs are present ("duck typing").
The SLxfig module <https://www.jedsoft.org/fun/slxfig/> makes
extensive use of this approach. --John
_______________________________________________
For list information, visit <http://jedsoft.org/slang/mailinglists.html>.
[2021 date index]
[2021 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]