It is currently Sun Jun 30, 2024 11:41 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: How to do Sub-Procedures
PostPosted: Thu Apr 22, 2021 8:39 am  (#1) 
Offline
GimpChat Member

Joined: Apr 20, 2021
Posts: 13
Dear Community,
I need some help

In the Post :: viewtopic.php?f=9&t=19333

I have done some Coding.
And in General the Work was nearly Complete.

But:
Be warned, doing this:
Code: Select all
(define image 1)
(define layer 2)

Will define image and layer for ALL scripts and might break other scripts.


From: Script Coder

So this to do for all needed Variables is very COOL but only the half Work.
So I tried to do not only Local Variables but Local Procedures too.
The Problem is:
I can't find any documentation how a Local Procedure will done
or Is it possible to have Local Procedures

So In hope of Help

Thomas Lahme


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: How to do Sub-Procedures
PostPosted: Thu Apr 22, 2021 9:07 am  (#2) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
Here's a way of doing local functions:
(define (script-fu_kp24_thing image drawable message colour option)
  (let*
    (
      (one 1)
      (two 2)
    )
    (define (my_add first second)
      (+ first second)
    )
    (define (my_multiply first second)
      (* first second)
    )
    (define (id_numbers first second)
      (gimp-message (string-append "id1: " (number->string first) " id2: " (number->string second)))
    )
    (gimp-message (number->string (my_add one two)))
    (gimp-message (number->string (my_multiply one two)))
    (id_numbers image drawable)   
  )
)


Top
 Post subject: Re: How to do Sub-Procedures
PostPosted: Thu Apr 22, 2021 9:52 am  (#3) 
Offline
GimpChat Member

Joined: Apr 20, 2021
Posts: 13
Ok,
I have edit my Program,
And my Local-Procedures are new not go direct Wrong
But it seams that the above by "let" defined Variables are not accessible from the Local Procedures
Can you please help me this Step to Runing-Code too.

Thanks
Thomas Lahme


Top
 Post subject: Re: How to do Sub-Procedures
PostPosted: Thu Apr 22, 2021 10:58 am  (#4) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
(define (script-fu_kp24_thing image drawable message colour option)
  (let*
    (
      (one 1)
      (two 2)
    )
    (define my_variable 3)
    (define (my_add first second)
      (+ first second)
    )
    (define (my_multiply first second)
      (* first second)
    )
    (define (mult_by_variable first)
      (* first my_variable)
    )
    (define (id_numbers first second)
      (gimp-message (string-append "id1: " (number->string first) " id2: " (number->string second)))
    )
    (gimp-message (number->string (my_add one two)))
    (gimp-message (number->string (my_multiply one two)))
    (gimp-message (string-append "Before: " (number->string (mult_by_variable two))))
    (set! my_variable 4)
    (gimp-message (string-append "After: " (number->string (mult_by_variable two))))
    (id_numbers image drawable)   
  )
)


Top
 Post subject: Re: How to do Sub-Procedures
PostPosted: Thu Apr 22, 2021 11:23 am  (#5) 
Offline
GimpChat Member

Joined: Apr 20, 2021
Posts: 13
Excuse me ;-)
I'm very new to Sheme - which is the Master-Language of Script-Fu
And I have never done anything with this before.
So please excuse my Beginner-Mistakes

But one Question more to your last Example in the last Post.
I have every time understand that a "Define" would create a global-Variable
So when I right understand you, inside a define Statement ...
... a inner "Define" would create a Global-Variable in this Define ...
Which is outer of the first Define a Local-Variable

Can you please say me is this new Understanding correct

In hope to learn the trick
Thomas Lahme


Top
 Post subject: Re: How to do Sub-Procedures
PostPosted: Thu Apr 22, 2021 11:47 am  (#6) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
Defining a variable (or procedure) inside a define limits that definition to the scope of the parent.

So in my example, my_variable only exists within script-fu_kp24_thing and cannot be accessed outside of it, but can be accessed by procedures also defined within script-fu_kp24_thing because they are in the same scope.

Kevin


Top
 Post subject: Re: How to do Sub-Procedures
PostPosted: Thu Apr 22, 2021 12:06 pm  (#7) 
Offline
GimpChat Member

Joined: Apr 20, 2021
Posts: 13
Ok,
I'm anything like a little bit sleepy so I think I will try it Tomorow
By the Way you are in my temporary Experience:
1. The most helpful People I meet Today :paint
2. The most helpful People to learn anything in Computer Science. :geek

So my respect for you :mrgreen:

A happy
Thomas Lahme


Top
 Post subject: Re: How to do Sub-Procedures
PostPosted: Fri Apr 23, 2021 6:54 am  (#8) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4752
ThomasLahme wrote:
Excuse me ;-)
I'm very new to Sheme - which is the Master-Language of Script-Fu


You are of course aware that you can also write your scripts in Python?

_________________
Image


Top
 Post subject: Re: How to do Sub-Procedures
PostPosted: Mon Apr 26, 2021 12:19 pm  (#9) 
Offline
GimpChat Member

Joined: Apr 20, 2021
Posts: 13
Yes I aware, but in the Days for Corona,
I have given Courses in Programming
And have made me my game to learn each necessary Programming-Language
Which is there outside in the Web of Community's

So I highly interested in Learning GIMP under Scheme.

So here Is my little Script which do by chance its Work.
And which most-fully don't Crash.

I have Commented the Code in the best I can.
But it must give a logical Mistake
== Which I will fix when I found it ==
So please is there outside anybody who find the Mistke
I will send you a Box of Sweets when you would call me the Mistake

Attachment:
File comment: This is my last Result.
When you have time to search the Mistake
Then please find the Mistake
When you find it tell me the Mistske
I swear I will give you a Box of chocolates

MyReadyMondrian.scm [4.66 KiB]
Downloaded 62 times


Thomas Lahme


Top
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Don't work procedures plug-in-bump-map, plug-in-displace

2


cron

* Login  



Powered by phpBB3 © phpBB Group