Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news2.arglkargh.de!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!postnews2.euro.net!news.wanadoo.nl!not-for-mail From: mhx@iae.nl (Marcel Hendrix) Subject: Matrices Newsgroups: comp.lang.forth Message-ID: <09181308028434@frunobulax.edu> Date: Sun, 27 Jan 2013 22:17:26 +0200 X-Newsreader: iForth 2.0 console (October 21, 2006) Lines: 33 Organization: Wanadoo NNTP-Posting-Date: 27 Jan 2013 21:17:28 GMT NNTP-Posting-Host: s529d937f.adsl.online.nl X-Trace: 1359321448 dr5.euro.net 249 82.157.147.127:54246 X-Complaints-To: abuse@wanadoo.nl Xref: csiph.com comp.lang.forth:19201 I have encountered a problem for which I don't immediately see a solution (maybe it won't need one in the Forth sense ;) Sometimes it is advantageous to NOT compile a word immediately. Is it possible to have 'delayed compilation?' An example is a word A* to multiply two dynamically allocated arrays. Because the address of the data and the number of rows and columns is unknown, the addressing of the matrix elements is very inefficient. In Forth it should be possible to compile A* AFTER it is detected that the matrices have been allocated (e.g. the first time A* is run). At that time many of the @s and !s will resolve to constant addresses, or at least access fixed rows or columns, and it will be known that the accesses are aligned or that the strides are powers of 2. Problems: How to detect code is run for the first time? How to detect that previously compiled code is still valid (no reallocate been done)? Note that the addresses of the matrices may be passed in locals. Assuming that the array syntax is a{{ row column }} @, it is of course possible to access a{{ efficiently by copying the addresses of rows and columns into locals (or on the stack) and then access elements row- or columnwise. However, as this is for my OPG project I'd like to always access the matrices the same, like a{{ row column }} @. Actually, in OPG the syntax will be a[r,c] where Forth doesn't even known if a is a vector or a (2D) matrix (the programmer knows, but does not know how to tell the compiler). -marcel