slang-users mailing list

[2021 Date Index] [2021 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: [slang-users] Can you do OO in Slang?


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]