Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Paul Rubin Newsgroups: comp.lang.forth Subject: Re: A New Forth Date: Sat, 08 Oct 2016 12:33:57 -0700 Organization: A noiseless patient Spider Lines: 46 Message-ID: <87wphivdne.fsf@nightsong.com> References: <9dc136b0-5a06-4bad-b719-0e94358896f1@googlegroups.com> <1f740c55-e4d9-4e0f-993c-346e55ff7438@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="590ea01354cf4bcbcd857d7ebbd88128"; logging-data="19142"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19YphJW4oa3zz7gvqTeSBYT" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:JfyuULelm7SprVIAxPirKJLe77o= sha1:INZ5sHVS/5wUm4gm1E504fsrWA0= Xref: csiph.com comp.lang.forth:51713 trans writes: > the Forth I am working on will be typed. ... primarily for the > multi-method dispatching it will allow... > : foo ( int int -- int ) ... ; > : foo ( int int int -- int ) ... ; > When deciding which foo to use based on the type signature if there > are three ints on the stack, does it use the first or the second > definition? Type based dispatching like C++'s sounds like a poor idea for a Forth-like language. The two basic choices are: 1) keeping with Forth's interactive style, let the second definition overwrite the first one while emitting a warning; or, 2) raise a compile-time error. > say if a word returns a float vs an integer based on some runtime > condition. I really don't think I want to restrict return values to a > single concrete signature. Then you're not writing a typed language. > That would make compilation a lot easier, but I fear it would make > programming in this Forth feel far too constrained. Am I right about > that? No not really. Forth makes what you're describing possible, but preferred Forth style is to avoid it and stay with static signatures. > I've been trying to find out how other static compilers handle this > situation but haven't found out yet. With variant types aka tagged unions. Stepping back a little, can I ask what the purpose of this project is? Do you have an application area and target where you want to use the compiler you're writing? Are you mostly just writing a compiler for fun (and there's nothing wrong with that)? Either way but especially if the latter, why Forth? Forth is the way it is partly because of its traditional philosophy of keeping its implementation very simple. There are fancy implementations out there, but they were written mostly to bring better performance to programs written with familiar Forth techniques. It sounds like you've been using C++. If you want exposure to fancier uses of type systems, you might give Haskell a try. http://learnyouahaskell.com is a good place to start.