Created
October 8, 2021 17:27
-
-
Save Vaguery/20bbf15ceb4d5e8fb862be24e5c75951 to your computer and use it in GitHub Desktop.
trying to understand Swift subclass collections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// KickInterpreter.swift | |
// Kick | |
// | |
// Created by Bill Tozier on 10/7/21. | |
// | |
import Foundation | |
protocol Pushable { | |
associatedtype Item | |
var push_type: String { get } | |
var value : Item { get } | |
} | |
protocol PushItem { | |
} | |
// push items | |
struct PushAtom<T> : PushItem,Pushable { | |
var value: T | |
var push_type: String | |
init(_ v: T, _ name: String = "") { | |
value = v | |
push_type = name | |
} | |
} | |
struct PushBlock: PushItem,Pushable { | |
var value: [PushItem] | |
var push_type = "codeblock" | |
init(_ v: PushItem ...) { | |
value = v | |
} | |
} | |
struct Foo { | |
var bar: String | |
init(_ bar:String) {self.bar = bar} | |
} | |
let b1 = PushAtom<Int64>(11) | |
let b2 = PushAtom<Double>(2.2) | |
let b3 = PushAtom<Foo>(Foo("baz")) | |
let block1 = PushBlock(b1,b2) | |
let block2 = PushBlock(block1,b3) | |
print(block.value[0].value) | |
// ERROR: Value of type 'PushItem' has no member 'value' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment