Author Topic: variables variables ...  (Read 4131 times)

0 Members and 1 Guest are viewing this topic.

vladimirzm

  • Guest
variables variables ...
« on: February 18, 2009, 01:45:15 PM »
Is there any way to know what variables (the symbol not the value) were assigned as arguments when calling a function?

Code: [Select]

(setq a 2)

(defun foo (b)
  (??? b) ; here ret val must be the symbol not the value
)


so: (foo a) must return "a" not 2

I hope somebody understand my english

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6941
  • AKA Daniel
Re: variables variables ...
« Reply #1 on: February 18, 2009, 02:02:20 PM »
Should this be in the lisp area?

vladimirzm

  • Guest
Re: variables variables ...
« Reply #2 on: February 18, 2009, 02:08:28 PM »
well i know this is imposible in lisp and i was thinking through arx could be..

MP

  • Seagull
  • Posts: 17454
Re: variables variables ...
« Reply #3 on: February 18, 2009, 02:09:39 PM »
What is driving the perceived need to return a symbol rather than a value?
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6941
  • AKA Daniel
Re: variables variables ...
« Reply #4 on: February 18, 2009, 02:19:18 PM »
well i know this is imposible in lisp and i was thinking through arx could be..

Oh ok, I don’t know off hand, but that doesn’t mean it can’t be done.  :mrgreen:

MP

  • Seagull
  • Posts: 17454
Re: variables variables ...
« Reply #5 on: February 18, 2009, 02:20:47 PM »
You can return a symbol, but if it is local to the function when evaluated it will return nil.

What's driving this again?

:)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Spike Wilbury

  • Guest
Re: variables variables ...
« Reply #6 on: February 18, 2009, 02:23:01 PM »
O puedes hacer tu pregunta en Español, si gustas....

vladimirzm

  • Guest
Re: variables variables ...
« Reply #7 on: February 18, 2009, 02:31:30 PM »
well i have to count a lot of plines and a lot of its vertex and a lot other entities, so i usually "iterate" through this items with something like:

(setq x (+ 1 x)) or (setq x (- 1 x)) and others... 

this is small and nothin complicated itself but -for me- type this a lot of times is absolutelly annoying. then a build my own version:

Code: [Select]

(DEFUN ++ (**)
  (SET ** (1+ (EVAL **)))
)
(DEFUN -- (**)
  (SET ** (1- (EVAL **)))
)


this works nice:
(++ 'a) add +1 to a
(-- 'a) decrements a by 1

i just wondering if i can avoid the qoute,  just (++ a) instead of (++ 'a)

Thnx by your answers

y gracias por dejarme preguntar en castellano, bueno esa es la idea, si en ARX se puede saber a que simbolo apunta una variable cuando se ejecuta una función.

MP

  • Seagull
  • Posts: 17454
Re: variables variables ...
« Reply #8 on: February 18, 2009, 02:49:36 PM »
I'd ditch the C++ envy functions and symbols approach and use local defuns that use the parent's vars to simplify the code if I deemed it a benefit. The defun ++ ... approach is less efficient and far more annoying to me than using the native 1+, 1- functions, but I acknowledge mileages greatly vary. Not being snotty, just candid. :)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Spike Wilbury

  • Guest
Re: variables variables ...
« Reply #9 on: February 18, 2009, 02:56:49 PM »
well i have to count a lot of plines and a lot of its vertex and a lot other entities, so i usually "iterate" through this items with something like:

(setq x (+ 1 x)) or (setq x (- 1 x)) and others... 

this is small and nothin complicated itself but -for me- type this a lot of times is absolutelly annoying. then a build my own version:

Code: [Select]

(DEFUN ++ (**)
  (SET ** (1+ (EVAL **)))
)
(DEFUN -- (**)
  (SET ** (1- (EVAL **)))
)


this works nice:
(++ 'a) add +1 to a
(-- 'a) decrements a by 1

i just wondering if i can avoid the qoute,  just (++ a) instead of (++ 'a)

Thnx by your answers

y gracias por dejarme preguntar en castellano, bueno esa es la idea, si en ARX se puede saber a que simbolo apunta una variable cuando se ejecuta una función.

Supongo que si, mas yo no he necesitado hacer algo asi... (la otra cosa es que en lisp ya no estoy al dia....)

Entre otras cosas, buscas una funcion en donde simplemente le coloques el simbolo (que fuese entero) y lo aumente? - tal vez yo pueda escribirla en arx (para version de 2007 o superior), solo ocupo tiempo libre para eso.

O.... buscas alguna funcion que regrese el tamaño de un contenedor - o acceso a los iteradores de arx? (contenedor es por ejemplo todos los puntos, o todas las lineas, etc,. )

por ejemplo:

Code: [Select]
AcDbBlockTableRecordPointer pBTR(acdbCurDwg()->currentSpaceId(), AcDb::kForRead);
if (pBTR.openStatus() != Acad::eOk) return;
AcDbBlockTableRecordIterator* pIterator = NULL;
if (pBTR->newIterator(pIterator) != Acad::eOk) return;
while ( !pIterator->done() )
{
AcDbObjectId objId;
pIterator->getEntityId(objId);
AcDbObjectPointer<AcDbPoint> pPoint(objId, AcDb::kForRead);
if(pPoint.openStatus() == Acad::eOk)
{
// aqui hacer algo con el punto o simplemente contarlo...
}
pIterator->step();
}
delete pIterator;

vladimirzm

  • Guest
Re: variables variables ...
« Reply #10 on: February 18, 2009, 03:21:47 PM »
Quote
I'd ditch the C++ envy functions and symbols approach and use local defuns that use the parent's vars to simplify the code if I deemed it a benefit. The defun ++ ... approach is less efficient and far more annoying to me than using the native 1+, 1- functions, but I acknowledge mileages greatly vary. Not being snotty, just candid.
yes, i think my ++ is not as efficient as just simple 1+, but i really prefer to spend a bit more than a half second (timed in 8.7mb file full of 3dplines) instead of typing a lot of times (setq ...). believe me, after several hours of coding i have to pass my eyes two or three times even in this simple (setq x (1+ x)) so, is absolutelly more easy to read (++ 'x), and y really don't care to spend that half second.

if only it were 1+ or 1- it would be nice but 1+ is non destructive function in plain lisp

Quote
Entre otras cosas, buscas una funcion en donde simplemente le coloques el simbolo (que fuese entero) y lo aumente?
exactamente eso. ;)
no importa si en un ARX ya que lo que estoy haciendo es una rutina que empaquetaré en un VLX con diálogos OpenDCL e incluso otros arx (doslib, runtime odcl, lsp... ) asi que un arx más no es problema.

i'm begginer in ARX so i really can't do it, i just wondering if that is posible.
thnx again.



Spike Wilbury

  • Guest
Re: variables variables ...
« Reply #11 on: February 18, 2009, 03:55:50 PM »
Quote
I'd ditch the C++ envy functions and symbols approach and use local defuns that use the parent's vars to simplify the code if I deemed it a benefit. The defun ++ ... approach is less efficient and far more annoying to me than using the native 1+, 1- functions, but I acknowledge mileages greatly vary. Not being snotty, just candid.
yes, i think my ++ is not as efficient as just simple 1+, but i really prefer to spend a bit more than a half second (timed in 8.7mb file full of 3dplines) instead of typing a lot of times (setq ...). believe me, after several hours of coding i have to pass my eyes two or three times even in this simple (setq x (1+ x)) so, is absolutelly more easy to read (++ 'x), and y really don't care to spend that half second.

if only it were 1+ or 1- it would be nice but 1+ is non destructive function in plain lisp

Quote
Entre otras cosas, buscas una funcion en donde simplemente le coloques el simbolo (que fuese entero) y lo aumente?
exactamente eso. ;)
no importa si en un ARX ya que lo que estoy haciendo es una rutina que empaquetaré en un VLX con diálogos OpenDCL e incluso otros arx (doslib, runtime odcl, lsp... ) asi que un arx más no es problema.

i'm begginer in ARX so i really can't do it, i just wondering if that is posible.
thnx again.




Let see if these two new functions help you in some way....

(for now is a debug arx, please run some tests and let me know if works for you, then if it is useful, I might post the source code too SLN)

Usage:

Code: [Select]
(setq tst 1)

(aumenta "tst")

(resta "tst")
« Last Edit: February 18, 2009, 03:59:28 PM by LE »

vladimirzm

  • Guest
Re: variables variables ...
« Reply #12 on: February 18, 2009, 04:48:56 PM »
that's nice but i'm afraid is a bit more difficult:
from scanned plans, i have lots of plines and lines and text, this should be organized taking into account other drawings, this time made by engineers directly in 3D with splines, what i have to do:
check Z value on parts of the drawing
add plines at equal distance if the difference between 2 plines (in height) is larger than X, this X change in the same drawing
these must have the same amount of vertex than the pline with more vertex (the pline above or below)
if the next 2 plines has a difference (in height) larger than X... the same, sometimes this vertex may have less or more points depending on terrain
finally transform plines to splines (not by pedit, obvious reasons i need splines not adapted plines)
and change color to some text depending on the height
put all in one drawing...
i'have decided to use lists instead of selection sets

believe it or not, isn't difficult to do, the difficult is to translate pseudo code into real code where things like (setq x (1+ x)) begins to appear everywhere. This is where (++ 'a) helps.

I hope you understand my english


kdub

  • Mesozoic relic
  • SuperMod
  • Swamp Rat
  • Posts: 1364
  • class keyThumper<T>:ILazy<T>
Re: variables variables ...
« Reply #13 on: February 18, 2009, 05:06:38 PM »

All else aside ...
Code: [Select]
(defun ++ (**)
    (set ** (1+ (eval **)))
)


(defun Test1 (/ a)
    (setq a 0)
    (repeat 1000
        (setq a (1+ a))
    )
)

(defun Test2 (/ a)
    (setq a 0)
    (repeat 1000
        (++ 'a)
    )
)

[quote]
(benchmark '((Test1) (Test2)))

Benchmarking [M.P. 2005] .............Elapsed milliseconds for 1024 iteration(s)/ relative Timing :

    (TEST2).....3672 / 5.7285 <slowest>
    (TEST1)......641 / 1 <fastest>[/quote]

I don't see the (++ 'a) as easier to read.
and I think the speed loss is a pretty good reason not to use it as well.
called Kerry in my other life

Sometimes the question is more important than the answer.
#ridesober

vladimirzm

  • Guest
Re: variables variables ...
« Reply #14 on: February 18, 2009, 06:47:00 PM »
i'm agree this is not more efficient, but this how it works:

1200 plines with all process of the command takes
0.446 secs with ++
0.143 secs with setq and 1+

i really dont care 0.303 secs for to be more confortable writing code, even if it takes one second i'll be happy. i'm thinking implement -even- an spinner at command line, meaby 0.25 secs more no problem.

(setq x (1+ x))  -->  (++ 'x)  not easy to read?  :?  here we are not agree.