Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - rickyboy

#1
To whomever runs this forum,



I agree with Greg (itistoday).  If you hand the reins over to him, it will be in good hands.



Hopefully you can contact Lutz and get an approval.  WDYT?



Best, Rick (rickyboy)
#2
Thanks for posting the puzzle and your solution, cameyo!



I found the same 3 you found.  I wish I could post them here but alas I'm getting the Internal Server Error page; so I'll just post a link to the code.  The solution printout is in a comment at the bottom.



Like Ralph, I could not think of anything besides brute-force, but I added a little wrinkle that reduced the number of iterations by 6 times, so that it would run faster and, for that reason, wouldn't be "too boring." :)



https://git.sr.ht/~rick/newlisp-cryptarithmetic-puzzle/tree/master/item/lisp%2Afun%3Dnewlisp.lsp">https://git.sr.ht/~rick/newlisp-cryptar ... ewlisp.lsp">https://git.sr.ht/~rick/newlisp-cryptarithmetic-puzzle/tree/master/item/lisp%2Afun%3Dnewlisp.lsp
#3
Grazie, Massimo!
#4
It says in the manual that those expressions are octal.
#5
newLISP in the real world / Re: List of indexes
May 12, 2021, 12:13:28 PM
You could also "factor out" the repeated code, but it may not make the code more readable.

(define (get-indices L (child 0) (parents '()) (result '()))
  (if (empty? L)
      result
      (get-indices (1 L) (+ 1 child) parents
        (append
          (snoc result (snoc parents child))
          (if (list? (L 0))
              (get-indices (L 0) 0 (snoc parents child))
              '())))))
#6
newLISP in the real world / Re: List of indexes
May 12, 2021, 12:12:54 PM
Here's a version that uses recursive calls in a classic way (think, SICP) where even the loop is handled by recursive call.  (Nota bene: This is not a good newLISP implementation because newLISP doesn't turn tail calls into loops; fdb's implementation is the better one for newLISP.)

(define (get-indices L (child 0) (parents '()) (result '()))
  (if (empty? L)
      result
      (list? (L 0))
      (get-indices (1 L) (+ 1 child) parents
                   (append (snoc result (snoc parents child))
                           (get-indices (L 0) 0 (snoc parents child))))
      (get-indices (1 L) (+ 1 child) parents
                   (snoc result (snoc parents child)))))


You will need this utility function, snoc, which acts like cons but does the reverse (it says it in the name lol :) : it takes the element argument and puts it at the end of the list.  (Note also that the arguments are reversed as compared with cons.)

(define (snoc xs x) (push x xs -1))
#7
Quote from: newBert post_id=25018 time=1619774817 user_id=147
I tried this, unpretentious: https://controlc.com/10370640">https://controlc.com/10370640

This is much easier to read!
#8
newLISP in the real world / Re: IDE for newLISP
April 10, 2021, 08:09:12 AM
I noticed that he had only one item under the heading "What's not quite ready:". We can suggest another item:



- The source code



:)
#9
Whither newLISP? / Re: "place" in the function "inc"
January 01, 2021, 11:09:12 AM
Hi octowuss, and welcome!


Quote from: octowuss post_id=24979 time=1609486240 user_id=1457
That doesn't make any sense [...] and wanted to learn more Lisp, but this version is full of these incomprehensible "gimmicks" that make it very difficult to work out how to use it!

Well, the OP was really asking about a very obscure "corner case" usage of `inc` to accomplish the task of `sum` and it's definitely not a normal usage (which is why you couldn't find it in the manual).



When, I first saw this many years ago, I had already been programming for many years in newLISP and didn't even know about it.  OTOH, it didn't affect my programming use cases at all (and probably nobody else's), because there is an idiomatic way to accomplish the same thing.



If you want to learn about how to define and use functions that "have memory" (like `sum`), consult the manual here: http://www.newlisp.org/downloads/newlisp_manual.html#func_memory">http://www.newlisp.org/downloads/newlis ... unc_memory">http://www.newlisp.org/downloads/newlisp_manual.html#func_memory.  The example right there actually has a version of `sum`!  (It's just has another name.)  Rewriting that here for our convenience, we have:


> (define (sum:sum x) (inc sum:current-total x))
(lambda (x) (inc sum:current-total x))
> (sum 1)
1
> (sum 1)
2
> (sum 2)
4
> (sum 3)
7
>


And the function definition has not been altered (per your requirement):


> sum:sum
(lambda (x) (inc sum:current-total x))
>


Quote from: octowuss post_id=24979 time=1609486240 user_id=1457
Also, why does the example have a 0 after the x in the parameter list for sum?

I can leave that out and the function still works!


That's just newLISP's way of setting a default value for a function parameter, to be used if the caller doesn't supply an argument value for it.  Many languages have this feature.  newLISP documents this fact in its manual here: http://www.newlisp.org/downloads/newlisp_manual.html#define">http://www.newlisp.org/downloads/newlis ... tml#define">http://www.newlisp.org/downloads/newlisp_manual.html#define



I hope you stick around and continue to use newLISP.  It is a very fun language! Happy hacking!
#10
newLISP and the O.S. / Re: fun with pledge()
October 07, 2020, 06:56:07 PM
Nice! 👍
#11
Your #! line looks wrong.
#12
newLISP in the real world / Re: values into mul
October 11, 2019, 04:40:14 PM
Use read-expr.


(println (mul 2 (read-expr abc)))
#13
newLISP in the real world / Re: Timing function problem
September 20, 2019, 10:30:55 AM
Quote from: "Lutz"Over time envrironment and stack memory gets fragmented by certain functions. The error forces a total low level freeing and reallocation of this memory. There is nothing we can do about it without slowing down everywhere, but it is a rare enough problem. Until now, I have never seen this before.

Thanks, Lutz!
#14
newLISP in the real world / Re: Timing function problem
September 20, 2019, 06:36:34 AM
cameyo, thank you for raising this issue!
#15
newLISP in the real world / Re: Timing function problem
September 20, 2019, 05:44:15 AM
Quote from: "cameyo"@rickyboy and @ralph.ronnquist

Sorry, I didn't explain myself well. The function i tried was "merge" with temporary heap function.

Yes, you are correct. I remember testing this myself before I first posted here (as I had the same idea as Ralph). I ruled that out as a possibility when I saw what you saw: the timings still grew. And that's why in my first post, I was willing to guess that the blame is the very large call stack (because the input lists were large enough). That's why in my second post, I reported that much smaller input lists don't seem to exhibit the problem.



Then I saw Ralph's "let helper function" function, and I glossed over it (thinking, "yeah, I tried that; not gonna work") and I got stuck on his sort-based function (because my thought was "oh yeah, duh; good one") and to me THAT was "Ralph's function". :)  (In my view, the let-helper version wasn't his serious submission; he was using it as a vehicle to get us to investigate that avenue ourselves, like a good teacher who will not do all the work for his students. ;)



However, as I said, I still don't know what causes this issue. I'm hoping that Lutz (there it is: I used the L word :) or another kind soul will look into it, because it looks to me to be more of a bug than a feature.