Jump to content

Easier to recursively build than recursively deconstruct... is it even doable? (yes!)


Recommended Posts

Posted (edited)

@Jef!

 

You are right - (mapcar '(lambda ( x ) ...) ... ) is fastest, but in lisp form... On the other side, when you compile (mapcar (function (lambda ( x ) ...)) ... ) into *.vlx then this is fastest... So it depends how you want to use your code - in lsp or compiled vlx or fas form... Beside all this - IMO if you code it with (function), still difference will be only significant, but if you tend to use (mapcar ''(( x ) ... ) ... ) the difference becomes remarkable and beside this - you can't compile it... So @hanhphuc  versions are IMO just for forum fun and speedy typing, nothing more than that... I use almost always in forums (mapcar '(lambda ( x ) ... ) ... ) and for me typing (lambda) isn't such a problem and still this yields the best performance in lisp form, as I think that would be the most common way of using forum codes...

 

[EDIT : Beside all this in one my example it turned out that (somefunction (function (lambda ( x ) ... )) ... ) was faster than (somefunction '(lambda ( x ) ...) ... ) either in compiled or lisp form... So finally I was right ab (function) function - if you strive for speed and have a time to write it doing it by using (function) function pays off... By my testings there is just small difference in favor of compiled file than lisp when (function) is used, so you can if you want clearly use lisp file coded with (function) and gain almost the same results...]

Edited by marko_ribar
Added [EDIT] note...
Posted
6 hours ago, marko_ribar said:

(mapcar ''(( x ) ... ) ... ) the difference becomes remarkable and beside this - you can't compile it... So @hanhphuc  versions are IMO just for forum fun and speedy typing, nothing more than that...

One thing I noticed, if you have the animate option enabled in vlide and use let's say  (mapcar ''((x)(1+ x)) '(1 2 3)), a source page opens and it display and it shows what is being processed

;;; Copied to window at 10:33 AM 9/5/18

(LAMBDA (X) (1+ X))

;;; End of text

I get that some want to compile and cannot use "(mapcar ''((x), so for that I'll give you that point, even if personally I don't compile my code, I do understand that position. I also get that derived from the result of my tests that approach was roughly 20% slower than using lambda. On other hand, it would seems that @Grrr found some interesting use that is based on the fact that it is a string rather than a function, and have shown it with an example. Maybe there could have been some other way (isn't there always another way?) to achieve the same, but my take is that if you want to learn how to use a screwdriver, you have to start by not being convinced that the hammer is the only tool that anyone should ever use. I would not even mention speedy typing, for a 6 chars difference it doesn't seem likely as a reason as to why they use that structure. I always like to explore, analyse and I'm always opened to learning new things, but regarding quote vs function, if I made some tests, explicitly saying what I tested, how, and shared the results that point in a direction 25/25 times, feel free to prove me otherwise in some other context. You are more than welcome to do so. But please don't come and just say "Beside all this in one my example it turned out that (somefunction (function (lambda ( x ) ... )) ... ) was faster than (somefunction '(lambda ( x ) ...) ... ) either in compiled or lisp form..." and end up with "So finally I was right" without sharing the said example. 

Posted

Sorry I can't share my code as I copyrighted it... You have to trust me in what I wrote, simply it turned that way by my testings... Of course you don't have to trust me, but I am not laying I am just saying what was result of timings of execution on one my example... You need to write something bigger and with exhaustive usage of syntax (somefunction (function (lambda ( ... )) ... ) and check timings of execution of two differently coded routines (different by that syntax implementations)...

Posted
On 9/6/2018 at 12:43 PM, marko_ribar said:

You have to trust me in what I wrote, simply it turned that way by my testings... Of course you don't have to trust me, but I am not laying I am just saying what was result of timings of execution on one my example... You need to write something bigger and with exhaustive usage of syntax

I've let that sink in for few days... I didn't ask for full disclosure of your copyrighted work, just a sample that is faster with function in lisp format. I do take this kind of comment in consideration, but in the end of the day my #1 criteria is the result of my own benchmarks for any given cases, like the one I shared. I'm not sure why you bring that down to trust, or even feel you need to mention that you are not lying. I merely stated that if I got the same result repeatedly, 25 times in a row, fully disclosing what I tested, how, and came to conclusion X, that you just cannot just come and tell me "in one my example it turned out that X was not the result I got, So finally I was right". The "So I was right", which *might be* seen as you implying that I'm wrong, (else wouldn't you have said "so finally depending on the situation we are both right"?), in itself is a thing. Since you implied that I was wrong, could I do otherwise than totally insist that you provide an example? 🤨

Even if I'm always opened minded to learn new things, one cannot expect me to disregard my own results, based on some arbitrary abstract conditions, like "I need to write something bigger ",  "with exhaustive usage of syntax". What does bigger mean? what is a more exhaustive usage of that kind of syntax? If it was about trust I probably would have ask for a proof. My #1 goal is to learn and get better. It is why I've asked for an example; abstract sentences don't increase my knowledge. On the other hand, concrete examples might.

Posted
On 9/1/2018 at 5:53 AM, Grrr said:

And its not that hard to understand it - 

knowing that '((x)(* (+ x 1) 2)) equals to (lambda(x)(* (+ x 1) 2))

 

 

 

Note that:

'((x) (* (+ x 1) 2))

Is actually equivalent to:

(defun-q foo (x) (* (+ x 1) 2))

 

 

  • Like 1
Posted (edited)

In an effort to hopefully provide some clarity to this thread, I'll try to shed some light on the performance aspects of the use of the function function, versus a quoted lambda expression, versus other alternatives.

 

There is indeed a verifiable performance improvement to be gained through the use of the function function over a quoted lambda expression when supplied as a functional argument for, say, a mapcar expression. However, this improvement is only realised when the code is compiled to an optimised VLX application.

 

The reason for this improvement is actually rather straightforward: when a VLX application is optimised, function evaluation is 'direct', meaning the interpreter no longer needs to evaluate the symbol which points to the function definition in order to evaluate the expression (i.e. the code behaves as if the function definition had been inserted in-line in place of the symbol referencing such function).

 

As such, when the function function is used, functional arguments can be similarly linked and optimised as the VLX compiler can identify the occurrence of the function (albeit still an anonymous function) ahead of time, and hence optimise evaluation of the expression in the same manner as a named function. Conversely, when an anonymous function is quoted (or equivalently, when a defun-q expression is expressed as a quoted literal), such expressions can only be evaluated during run-time and hence cannot be linked & optimised in the manner described above.

Edited by Lee Mac
  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...