2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -0,0 +1,42 @@
module cg
implicit none
type, abstract :: eatable
end type eatable
type, extends(eatable) :: carrot_t
end type carrot_t
type :: brick_t; end type brick_t
type :: foodbox
class(eatable), allocatable :: food
contains
procedure, public :: add_item => add_item_fb
end type foodbox
contains
subroutine add_item_fb(this, f)
class(foodbox), intent(inout) :: this
class(eatable), intent(in) :: f
allocate(this%food, source=f)
end subroutine add_item_fb
end module cg
program con_gen
use cg
implicit none
type(carrot_t) :: carrot
type(brick_t) :: brick
type(foodbox) :: fbox
! Put a carrot into the foodbox
call fbox%add_item(carrot)
! Try to put a brick in - results in a compiler error
call fbox%add_item(brick)
end program con_gen

View file

@ -5,10 +5,10 @@ isEdible=:3 :0
coclass'FoodBox'
create=:3 :0
assert isEdible_Connoisseur_ type=:y
collection=: 0#y
)
add=:3 :0"0
'inedible' assert type e. copath y
'inedible' assert isEdible_Connoisseur_ y
collection=: collection, y
EMPTY
)

View file

@ -1,4 +1,4 @@
lunch=:(<'Apple') conew 'FoodBox'
lunch=:'' conew 'FoodBox'
a1=: conew 'Apple'
a2=: conew 'Apple'
add__lunch a1

View file

@ -2,8 +2,8 @@ subset Eatable of Any where { .^can('eat') };
class Cake { method eat() {...} }
role FoodBox[Eatable ::T] {
has T %.foodbox;
role FoodBox[Eatable] {
has %.foodbox;
}
class Yummy does FoodBox[Cake] { } # composes correctly

View file

@ -0,0 +1,18 @@
class Foodbox
def initialize (*food)
raise ArgumentError, "food must be eadible" unless food.all?{|f| f.respond_to?(:eat)}
@box = food
end
end
class Fruit
def eat; end
end
class Apple < Fruit; end
p Foodbox.new(Fruit.new, Apple.new)
# => #<Foodbox:0x00000001420c88 @box=[#<Fruit:0x00000001420cd8>, #<Apple:0x00000001420cb0>]>
p Foodbox.new(Apple.new, "string can't eat")
# => test1.rb:3:in `initialize': food must be eadible (ArgumentError)