List context - performance

Started by Tim Johnson, September 29, 2009, 12:09:51 PM

Previous topic - Next topic

Jeff

#15
Performance-wise, something like this would be simpler and faster:


(define-macro (extend)
  (push (eval (args 1)) (eval (args 0)) -1))

(setf lst '(1 2))
(extend lst 3) ; => (1 2 3)
lst ; => (1 2 3)
(extend lst 4) ; => (1 2 3 4)
lst ; => (1 2 3 4)
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

cormullion

#16
Quote(push (eval (args 1)) (eval (args 0)) -1)


Clever stuff! Looks simple, but only after someone else does it... :)

Tim Johnson

#17
Using the approach that I describe above, I wrote a series of vimscript

functions that initialize an object such as I've shown interest in and shown

an example of:
" ---------------------------------------------------------------------------------------
"  Given the variable name typed in, expands to a general set statement
" --------------------------------------------------------------------------------------
function! NewlispQuickSet()
  let wrd=expand("<cWORD>")
exe "norm! bdwa(set '" . wrd . " )<Left>"
endfunction
" -----------------------------------------------------------------------------
" Given the variable name typed in, expands to a global initializer
" expression containing an initializer function
" Example: foo => (set 'foo (List! "foo"))
" ----------------------------------------------------------------------------
function! NewlispInitGlobalObject(o)
  let w=expand("<cWORD>")
exe "norm! bdwa(set '" . w . "(" . a:o . "! "" . w . "" ))<Left><Left>"
endfunction
" ----------------------------------------------------------------------------
" Given the variable name typed in, expands to a local initializer
" as would be contained in a let() initializer expression
" Example: foo => (foo (List! "foo"))
" ---------------------------------------------------------------------------
function! NewlispInitLocalObject(o)
  let w=expand("<cWORD>")
exe "norm! bdwa(" . w . "(" . a:o . "! "" . w . "" ))<Left><Left>"
endfunction
" --------------------------------------------------------------------

Note: The last two functions expand to a particular coding style, so

if you have stumbled across this, make sure to read my posts in this thread.

Also, for you vimmers, these functions are in turn called from functions which

are agnostic to the programming language.

so if you call them directly, then you'll need to add "a" to get back into

insert mode at the right place.

Key mapping examples:
inoremap <T-Space>      <Esc>:call StdInitializeVariable()<CR>a
inoremap <F2>l      <Esc>:call StdInitGlobalList()<CR>a
inoremap <F2>m      <Esc>:call StdInitLocalList()<CR>a

Note <T-Space> That is the vimscript notation for the "Super" modifier" following

by "Space"

Thanks again for this thread. I'm going to rip off a whole lot of the examples

submitted for my List! context.

cheers

tim
Programmer since 1987. Unix environment.