Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 17th June 2020, 13:24   #1  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,869
Else if and script review of my crappy code

Hi there,
I was trying to make the conversion through my LUTs a bit more user friendly, so I fired up AVSPmod and gave it a shot, however I'm puzzled on a few things.

Question 1: matrices of linear transformation (LUTs) can be quite large, depending on their size. Should I hard-link them to a folder in my code and ask users to put the LUTs in a specific folder all the time, or should I include them in my avsi script somewhere? If the latter is chosen, how can I pass them to Cube()? You can see that I left the path blank where there's "myvalue".
I mean, I know how to pass a string, but if I include them in the file it would be an array, not a string...
Ideally I would like to include them all together in one big avsi file.

Question 2: If statement work like a charm in Avisynth, however if I don't put an else, it complains... Ideally, I'd like to do:

If (aaa == true)
{
do something
}
else if ( bbb == true)
{
do something else
}

however in the current implementation when I use "?" it expects a ":" which is "else", not "else if".
How can I get an else if?

Code:
function LinearTransformation(clip clp, string "Input" string "Output")

 {
         Assert( ( clp.isYV12() || clp.isYUY2() || clp.isYV16() || clp.isYV24() || clp.Is420() || clp.Is422() || clp.Is444() || clp.IsPlanarRGB() || 
                      clp.IsRGB() || clp.IsRGB24() || clp.IsRGB32() || clp.IsRGB48() || clp.IsRGB64()) ? true : false, 
                      chr(10) + "Color Format not supported, only 4:2:0, 4:2:2, 4:4:4 and RGB planar are supported" + chr(10))
        
        source = clp
        clp.IsYV12() ? original="YV12"
        clp.IsYUY2() ? original="YUY2"
        clp.IsYV16() ? original="YV16"
        clp.IsYV24() ? original="YV24"
        clp.Is420() ? original="YUV420"
        clp.Is422() ? original="YUV422"
        clp.Is444() ? original="YUV444"
        clp.IsRGB() ? original="RGB"
        clp.IsRGB24() ? original="RGB24"
        clp.IsRGB32() ? original="RGB32"
        clp.IsRGB48() ? original="RGB48"
        clp.IsRGB64() ? original="RGB64"

        clp = clp.IsPlanarRGB() ?  clp : clp.ConvertBits(bits=16).ConvertToPlanarRGB()

        BT601_NTSC_to_BT709=myvalues
        BT601_PAL_to_BT709=myvalues
        BT709_to_BT601_NTSC=myvalues
        BT709_to_BT601_PAL=myvalues
        BT709_to_HLG=myvalues
        BT709_to_PQ=myvalues
        BT2100_HDR_PQ_to_BT2020_SDR=myvalues
        CLog3_to_BT709=myvalues
        CLog3_to_HDR_HLG=myvalues
        CLog3_to_HDR_PQ=myvalues
        DCIXYZ_to_YUVBT709=myvalues
        HLG_to_BT709=myvalues
        HLG_to_PQ=myvalues
        LogC_to_BT709=myvalues
        PQ_to_BT709_v1=myvalues
        PQ_to_HLG=myvalues
        Slog2_to_BT709=myvalues
        Slog3_to_BT709=myvalues
        Vlog_to_BT709=myvalues
        YUVBT709_to_DCIXYZ=myvalues
        Z-Log_to_BT709=myvalues
        
        Input="Linear_BT601_NTSC" && Output="LinearBT709" ? Cube(clp, BT601_NTSC_to_BT709, fullrange=true) : Null(copy="none")
        Input="Linear_BT601_PAL" && Output="BT601_PAL_to_BT709" ? Cube(clp, BT601_PAL_to_BT709, fullrange=true) : Null(copy="none")
        Input="LinearBT709" && Output="Linear_BT601_NTSC" ? Cube(clp, BT709_to_BT601_NTSC, fullrange=true) : Null(copy="none")
        Input="LinearBT709" && Output="Linear_BT601_PAL" ? Cube(clp, BT709_to_BT601_PAL, fullrange=true) : Null(copy="none")
        Input="LinearBT709" && Output="BT2020_HLG" ? Cube(clp, BT709_to_HLG, fullrange=true) : Null(copy="none")
        Input="LinearBT709" && Output="BT2100_PQ" ? Cube(clp, BT709_to_PQ, fullrange=true) : Null(copy="none")
        Input="BT2100_PQ" && Output="Linear_BT2020" ? Cube(clp, BT2100_HDR_PQ_to_BT2020_SDR, fullrange=true) : Null(copy="none")
        Input="CLog3" && Output="Linear_BT709" ? Cube(clp, CLog3_to_BT709, fullrange=true) : Null(copy="none")
        Input="CLog3" && Output="BT2020_HLG" ? Cube(clp, CLog3_to_HDR_HLG, fullrange=true) : Null(copy="none")
        Input="CLog3" && Output="BT2100_PQ" ? Cube(clp, CLog3_to_HDR_PQ, fullrange=true) : Null(copy="none")
        Input="DCI_XYZ" && Output="Linear_BT709" ? Cube(clp, DCIXYZ_to_YUVBT709, fullrange=true) : Null(copy="none")
        Input="BT2020_HLG" && Output="Linear_BT709" ? Cube(clp, HLG_to_BT709, fullrange=true) : Null(copy="none")
        Input="BT2020_HLG" && Output="BT2100_PQ" ? Cube(clp, HLG_to_PQ, fullrange=true) : Null(copy="none")
        Input="LogC" && Output="Linear_BT709" ? Cube(clp, LogC_to_BT709, fullrange=true) : Null(copy="none")
        Input="BT2100_PQ" && Output="Linear_BT709" ? Cube(clp, PQ_to_BT709_v1, fullrange=true) : Null(copy="none")
        Input="BT2100_PQ" && Output="BT2020_HLG" ? Cube(clp, PQ_to_HLG, fullrange=true) : Null(copy="none")
        Input="SLog2" && Output="Linear_BT709" ? Cube(clp, Slog2_to_BT709, fullrange=true) : Null(copy="none")
        Input="SLog3" && Output="Linear_BT709" ? Cube(clp, Slog3_to_BT709, fullrange=true) : Null(copy="none")
        Input="VLog" && Output="Linear_BT709" ? Cube(clp, Vlog_to_BT709, fullrange=true) : Null(copy="none")
        Input="Linear_BT709" && Output="DCI_XYZ" ? Cube(clp, YUVBT709_to_DCIXYZ, fullrange=true) : Null(copy="none")
        Input="Linear_BT709" && Output="DCI_XYZ" ? Cube(clp, Z-Log_to_BT709, fullrange=true) : Null(copy="none")
        
        original="YV12" ? last.ConvertBits(bits=8, dither=1).ConverttoYV12() : last
        original="YUY2" ? last.ConvertBits(bits=8, dither=1).ConverttoYUY2() : last
        original="YV16" ? last.ConvertBits(bits=8, dither=1).ConverttoYV16() : last
        original="YV24" ? last.ConvertBits(bits=8, dither=1).ConverttoYV24() : last
        original="YUV420" ? last.ConverttoYUV420() : last
        original="YUV422" ? last.ConverttoYUV422() : last
        original="YUV444" ? last.ConverttoYUV444() : last
        original="RGB" ? last.ConverttoRGB() : last
        original="RGB24" ? last.ConverttoRGB24() : last
        original="RGB32" ? last.ConverttoRGB32() : last
        original="RGB48" ? last.ConverttoRGB48() : last
        original="RGB64" ? last.ConverttoRGB64() : last
        
        
        
}

Last time I tried to do something with the Avisynth Scripting it was with VideoTek() and the sober-at-that-time StainlessS came into help. Will he come in rescue this time as well or will it be someone else? Who knows...

By the way, sorry in advance to whoever will read my crappy code

Last edited by FranceBB; 17th June 2020 at 13:29.
FranceBB is online now   Reply With Quote
Old 17th June 2020, 13:57   #2  |  Link
ChaosKing
Registered User
 
Join Date: Dec 2005
Location: Germany
Posts: 1,795
Isn't elseif() {} just more or less a short version of else { if() {} } ?

You can use nested inline if statements

Code:
blankclip()
a = false
b = false

text = a ? "a=true" : b ? "b=true" : "b=false"
subtitle(text)
__________________
AVSRepoGUI // VSRepoGUI - Package Manager for AviSynth // VapourSynth
VapourSynth Portable FATPACK || VapourSynth Database
ChaosKing is offline   Reply With Quote
Old 17th June 2020, 16:10   #3  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
I would expect the below line to fail due to missing line continuation '\' characters on extra lines
Code:
         Assert( ( clp.isYV12() || clp.isYUY2() || clp.isYV16() || clp.isYV24() || clp.Is420() || clp.Is422() || clp.Is444() || clp.IsPlanarRGB() || 
               \       clp.IsRGB() || clp.IsRGB24() || clp.IsRGB32() || clp.IsRGB48() || clp.IsRGB64()) ? true : false, 
               \       chr(10) + "Color Format not supported, only 4:2:0, 4:2:2, 4:4:4 and RGB planar are supported" + chr(10))
Below '== true' is superfluous when testing bool (which can be only true or false), compare to either true or false will actually fetch Global variable 'true' or 'false'
from Global variables table, and global variables are really quite slow to access.

Code:
If (aaa == true)
{
do something
}
else if ( bbb == true)
{
do something else
}
so instead of eg 'a == true', need (as ChaosKing did) just 'a', as in
Code:
text = a ? "a=true" : b ? "b=true" : "b=false"
When using as above, the test on 'a' will (I think) be done directly by parser, and is quick, same for '!a' which is equivalent to 'a==false'.

Quote:
and the sober-at-that-time
I am deeply offended by that line, I'll have you know that I have never knowingly been sober without good reason.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 17th June 2020 at 16:13.
StainlessS is offline   Reply With Quote
Old 17th June 2020, 16:26   #4  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
Quote:
Originally Posted by StainlessS View Post
so instead of eg 'a == true', need (as ChaosKing did) just 'a', as in
Code:
text = a ? "a=true" : b ? "b=true" : "b=false"
I like these kind of conditionals, you can do cool stuff such as this:
Code:
bool isLeapYear(int year )
{
  return  year % 400 ? year % 100 ? year % 4 ? false : true : false : true;
}
Well, this is C code but you get the idea.
__________________
Groucho's Avisynth Stuff
Groucho2004 is offline   Reply With Quote
Old 17th June 2020, 17:07   #5  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Originally Posted by StainlessS View Post
so instead of eg 'a == true', need (as ChaosKing did) just 'a', as in
Code:
text = a ? "a=true" : b ? "b=true" : "b=false"
In actual fact it should perhaps be this
Code:
text = a ? "a=true" : b ? "b=true" : "a=false && b=false"
Quote:
Well, this is C code but you get the idea.
Avs script
Code:
Function isLeapYear(int year) { return  (year % 400)!=0 ? (year % 100)!=0 ? (year % 4)!=0 ? false : true : false : true }

for(i=0,3000,100) {
    RT_DebugF("%4d] %s",i,i.isLeapYear)
}
Code:
00000436    0.19900697  RT_DebugF:    0] True
00000437    0.19911566  RT_DebugF:  100] False
00000438    0.19921313  RT_DebugF:  200] False
00000439    0.19930732  RT_DebugF:  300] False
00000440    0.19982870  RT_DebugF:  400] True
00000441    0.19983993  RT_DebugF:  500] False
00000442    0.19997905  RT_DebugF:  600] False
00000443    0.20008123  RT_DebugF:  700] False
00000444    0.20018087  RT_DebugF:  800] True
00000445    0.20028014  RT_DebugF:  900] False
00000446    0.20037977  RT_DebugF: 1000] False
00000447    0.20047905  RT_DebugF: 1100] False
00000448    0.20057796  RT_DebugF: 1200] True
00000449    0.20067760  RT_DebugF: 1300] False
00000450    0.20077759  RT_DebugF: 1400] False
00000451    0.20087615  RT_DebugF: 1500] False
00000452    0.20097686  RT_DebugF: 1600] True
00000453    0.20107687  RT_DebugF: 1700] False
00000454    0.20117651  RT_DebugF: 1800] False
00000455    0.20127578  RT_DebugF: 1900] False
00000456    0.20137469  RT_DebugF: 2000] True
00000457    0.20147397  RT_DebugF: 2100] False
00000458    0.20157360  RT_DebugF: 2200] False
00000459    0.20167288  RT_DebugF: 2300] False
00000460    0.20177324  RT_DebugF: 2400] True
00000461    0.20187323  RT_DebugF: 2500] False
00000462    0.20197323  RT_DebugF: 2600] False
00000463    0.20207323  RT_DebugF: 2700] False
00000464    0.20217106  RT_DebugF: 2800] True
00000465    0.20227033  RT_DebugF: 2900] False
00000466    0.20236960  RT_DebugF: 3000] False
I guess Grouchy also has Roman and Chinese Leap months, and also Leap seconds well sewn up too.

EDIT:
Or maybe easier figuroutable,
Code:
Function isLeapYear(int year) { return  (year % 400)==0 ? true : (year % 100)==0 ? false : (year % 4)==0 }
EDIT: Oops, added in blue
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 17th June 2020 at 17:31.
StainlessS is offline   Reply With Quote
Old 17th June 2020, 20:53   #6  |  Link
ChaosKing
Registered User
 
Join Date: Dec 2005
Location: Germany
Posts: 1,795
Quote:
Originally Posted by StainlessS View Post
In actual fact it should perhaps be this
Code:
text = a ? "a=true" : b ? "b=true" : "a=false && b=false"
If you care about a=false, then yes. But a=false wasn't in FranceBB example, so...
__________________
AVSRepoGUI // VSRepoGUI - Package Manager for AviSynth // VapourSynth
VapourSynth Portable FATPACK || VapourSynth Database
ChaosKing is offline   Reply With Quote
Old 18th June 2020, 09:11   #7  |  Link
Boulder
Pig on the wing
 
Boulder's Avatar
 
Join Date: Mar 2002
Location: Finland
Posts: 5,717
Quote:
Originally Posted by Groucho2004 View Post
I like these kind of conditionals, you can do cool stuff such as this:
Code:
bool isLeapYear(int year )
{
  return  year % 400 ? year % 100 ? year % 4 ? false : true : false : true;
}
Well, this is C code but you get the idea.
Hehe, the chain of what ifs gets quite confusing there. Are they parsed like parentheses so that the last "true" applies to the case of "year % 400" being false?
__________________
And if the band you're in starts playing different tunes
I'll see you on the dark side of the Moon...
Boulder is offline   Reply With Quote
Old 18th June 2020, 12:28   #8  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
Quote:
Originally Posted by Boulder View Post
Hehe, the chain of what ifs gets quite confusing there. Are they parsed like parentheses so that the last "true" applies to the case of "year % 400" being false?
Nested conditional ternary operators:
https://stackoverflow.com/questions/...-operator-loop
https://stackoverflow.com/questions/...-of-evaluation
__________________
Groucho's Avisynth Stuff
Groucho2004 is offline   Reply With Quote
Old 18th June 2020, 16:17   #9  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: void
Posts: 2,633
it's actually a binary tree structure, you go to the left child if the condition is satisfied, otherwise you go to the right child, the evaluation completes whenever you reach a leaf node.

root: x % 400 != 0, left child: node A, right child (leaf): true
node A: x % 100 !=0, left child: node B, right child (leaf): false
node B: x % 4 != 0, left child (leaf): false, right child (leaf): true

there're better ways to handle this kinda stuff than cryptic nested ?: operators
feisty2 is offline   Reply With Quote
Old 18th June 2020, 16:23   #10  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by feisty2 View Post
there're better ways to handle this kinda stuff than cryptic nested ?: operators
Obviously.
But the whole point of Groucho's amusing post was to make it look as cryptic as possible.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 18th June 2020, 16:57   #11  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: void
Posts: 2,633
Quote:
Originally Posted by Gavino View Post
make it look as cryptic as possible.
sure

Code:
auto btree_eval(auto x, auto cond, auto lchild, auto ...p) {
    if (cond(x))
        return lchild;
    else
        if constexpr (sizeof...(p) == 0)
            return !lchild;
        else
            return btree_eval(x, p...);
}

for (auto x = 0; x <= 3000; x += 100)
    std::cout << x << ": " << btree_eval(x, 
    [](auto x) { return x % 400 == 0; }, true,
    [](auto x) { return x % 100 == 0; }, false,
    [](auto x) { return x % 4 == 0; }, true
    ) << std::endl;
https://godbolt.org/z/WbHspP
feisty2 is offline   Reply With Quote
Old 18th June 2020, 18:12   #12  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
Quote:
Originally Posted by Gavino View Post
Obviously.
But the whole point of Groucho's amusing post was to make it look as cryptic as possible.
Hehe, yeah.

However, if you think that's cryptic, check these out.
__________________
Groucho's Avisynth Stuff
Groucho2004 is offline   Reply With Quote
Old 18th June 2020, 18:55   #13  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
More Crappy Code, not written by FranceBB [Other people can be equally adept in the crappy code department]

Code:
# C/CPP can treat int 0 as false, and anything other than 0 as true,
#     so C/CPP can make decision based on value of int being zero or non-zero.
# AVS can only make decision on bool so to do same in AVS must convert int into bool,
#     so where x is int, must use eg,
#         C:=  (x),   <=====>    AVS:= (x!=0)      # True if x!=0, otherwise False (as x==0) : REMark (x==0) and (x!=0) both produce a bool.
#         C:= (!x),   <=====>    AVS:= (x==0)      # True if x==0, otherwise False (as x!=0)
/*
    # Grouchy C/CPP version
    bool isLeapYear_G(int year ) {
        return  year % 400 ? year % 100 ? year % 4 ? false : true : false : true;
    }
*/

# AVS conversion of Grouchy C/CPP ternary conditional method. (Without Shortcut)
Function isLeapYear_G1(int year) { #             <<<<<- Without Shortcut->>>>
    Answer = (year % 400)!=0 ? (year % 100)!=0 ? (year % 4)!=0 ? false : true : false : true
    return Answer
}

# AVS conversion #2 of Grouchy C/CPP, if/else method.
Function isLeapYear_G2(int year) {
    if((year % 400)!=0) {            # TEST_1
        if((year % 100)!=0) {        # TEST_2
            if((year % 4)!=0) {      # TEST_3
                Answer = false       # ANS_3B : TEST_1 SUCCEED, TEST_2 SUCCEED, return false based on TEST_3 SUCCEED
            } else {
                Answer = true        # ANS_3A : TEST_1 SUCCEED, TEST_2 SUCCEED, return true  based on TEST_3 FAIL
            }
        } else {
            Answer = false           # ANS_2  : TEST_1 SUCCEED, TEST_2 FAIL, 2nd least complex solution.
        }
    } else {
        Answer = true                # ANS_1  : If TEST_1 FAILS, then this is the least complex solution in the problem domain, ie we got the answer with least testing.
    }
    return Answer
}

# AVS conversion #3 of Grouchy C/CPP ternary conditional method, with logic shortcut
Function isLeapYear_G3(int year) { #             <<-SHORTCUT=>>>
    Answer = (year % 400)!=0 ? (year % 100)!=0 ? ((year % 4)==0) : false : true
    return Answer
}

# AVS conversion #4 of Grouchy C/CPP, if/else method, with logic shortcut.
Function isLeapYear_G4(int year) {
    if((year % 400)!=0) {            # TEST_1
        if((year % 100)!=0) {        # TEST_2
            Answer = ((year % 4)==0) # TEST_3 : ANS_3 : TEST_1 and TEST_2 SUCCEED, # SHORTCUT, Get true/false using ((year % 4)==0) instead of explict assignment of true or false.
        } else {
            Answer = false           # ANS_2  : TEST_1 SUCCEED, TEST_2 FAIL, 2nd least complex solution.
        }
    } else {
        Answer = true                # ANS_1  : If TEST_1 FAIL, then this is the least complex solution in the problem domain, ie we got the answer with least testing.
    }
    return Answer
}

# AVS conversion using more easily figuroutable ternary conditional method.
Function isLeapYear_S1(int year) {
    Answer = ((year % 400)==0) ? true : ((year % 100)==0) ? false : ((year % 4)==0) ? true : false
    return Answer
}

# AVS conversion using more easily figuroutable, if/else method.
Function isLeapYear_S2(int year) {
    if ((year % 400)==0) {           # TEST_1
        Answer = true                # ANS_1  : If TEST_1 SUCCEEDS, then this is the least complex solution in the problem domain, ie we got the answer with least testing.
    } else if((year % 100)==0) {     # TEST_2
        Answer = false               # ANS_2  : TEST_1 FAILS, TEST_2 SUCCEEDS, 2nd least complex solution.
    } else if ((year % 4)==0) {      # TEST_3
        Answer = true                # ANS_3A : TEST_1 FAILS, TEST_2 FAILS, return true   based on TEST_3 SUCCEED
    } else {
        Answer = false               # ANS_3B : TEST_1 FAILS, TEST_2 FAILS, return false  based on TEST_3 FAIL
    }
    return Answer
}

# AVS conversion using more easily figuroutable ternary conditional method, with logic shortcut
Function isLeapYear_S3(int year) { #                                <<-SHORTCUT=>>>
    Answer = ((year % 400)==0) ? true : ((year % 100)==0) ? false : ((year % 4)==0)   # Get final true/false using ((year % 4)==0) instead of explict assignment of true or false.
    return Answer
}

# AVS conversion using more easily figuroutable if/else method, with logic shortcut
Function isLeapYear_S4(int year) {
    if ((year % 400)==0) {           # TEST_1
        Answer = true                # ANS_1  : If TEST_1 SUCCEEDS, then this is the least complex solution in the problem domain, ie we got the answer with least testing.
    } else if((year % 100)==0) {     # TEST_2
        Answer = false               # ANS_2  : TEST_1 FAILS, TEST_2 SUCCEEDS, 2nd least complex solution.
    } else { #   <<-SHORTCUT=>>>
        Answer = ((year % 4)==0)     # TEST_3 : ANS_3 : TEST_1 FAIL, TEST_2 FAIL, # SHORTCUT, Get true/false using ((year % 4)==0) instead of explict assignment of true or false.
    }
    return Answer
}

##################
##################
##################

ErrCnt=0
SSS=""
for(i=0,3000,1) {
    G1=isLeapYear_G1(i)
    G2=isLeapYear_G2(i)
    G3=isLeapYear_G3(i)
    G4=isLeapYear_G4(i)
    S1=isLeapYear_S1(i)
    S2=isLeapYear_S2(i)
    S3=isLeapYear_S3(i)
    S4=isLeapYear_S4(i)
    AllSame = (G1==G2==G3==G4==S1==S2==S3==S4)   # Cheeky jiggery pokery scripting, did not know if it would work, similar to eg Assert(0 <= digit <= 9,"Error 0 <= digit <= 9")
    ErrCnt = (!AllSame) ? ErrCnt + 1 : ErrCnt    # Check for errors on All Years
    S=RT_String("%4d] %.1s%.1s%.1s%.1s%.1s%.1s%.1s%.1s :: All Same=%s",i,G1,G2,G3,G4,S1,S2,S3,S4,AllSame)
    RT_DebugF("%s",S,Name="LEAP: ")
    if((i % 100)==0) {                          # Only Show every 100 years
        SSS=RT_string("%s%s\\n",SSS,S)
    }
}
RT_DebugF("\nErrCnt=%d",ErrCnt,Name="LEAP: ")

BlankClip(width=480,height=640)
SSS=RT_string("%s\\nErrCnt=%d",SSS,ErrCnt)
Subtitle(SSS,font="CourierNew",lsp=0)
Return Last
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 18th June 2020 at 19:09.
StainlessS is offline   Reply With Quote
Old 18th June 2020, 18:59   #14  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: void
Posts: 2,633
stainless, you skipped my version at #11, not cool
feisty2 is offline   Reply With Quote
Old 18th June 2020, 19:11   #15  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Sorry, I got no idea what that lot does [also I did not really see it]
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 18th June 2020, 19:15   #16  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: void
Posts: 2,633
Quote:
Originally Posted by StainlessS View Post
Sorry, I got no idea what that lot does [also I did not really see it]
it's just c++, click the link and see the code being compiled and executed at real time. you old folks must be very familiar with c++, right?
feisty2 is offline   Reply With Quote
Old 18th June 2020, 19:26   #17  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
That looks a handy site if your wanting to clue up on Assembler, thanks, copied link.
[GeeksForGeeks.org has a similar online compiler test thingy (without asm)] :- https://www.geeksforgeeks.org/

Quote:
you old folks must be very familiar with c++, right?
Not really, does it work on XP ?

EDIT: And not really relevant, but, did you know that a Venus day is longer than a Venus year ? [shock horror, maybe its a leap day].
["Not a lot of people know that" (In the melodic voice of Michael Caine)].
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 18th June 2020 at 19:42.
StainlessS is offline   Reply With Quote
Old 18th June 2020, 19:49   #18  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: void
Posts: 2,633
Quote:
Originally Posted by StainlessS View Post
That looks a handy site if your wanting to clue up on Assembler, thanks, copied link.
[GeeksForGeeks.org has a similar online compiler test thingy (without asm)] :- https://www.geeksforgeeks.org/


Not really, does it work on XP ?
sure, as long as you can find a compiler that supports c++20 and works on xp, there's no wording in the c++ standard that excludes xp support.

I translated the code at #11 to a more "nostalgic" kind of c++ that you grandpas might find easier to understand.

https://godbolt.org/z/acBwqF

Code:
#include <iostream>

typedef bool(*cond_type)(int);

bool btree_eval(int x, cond_type cond, bool lchild) {
    if (cond(x))
        return lchild;
    else
        return !lchild;
}

template<typename ...T>
bool btree_eval(int x, cond_type cond, bool lchild, T ...p) {
    if (cond(x))
        return lchild;
    else
        return btree_eval(x, p...);
}

bool cond1(int x) {
    return x % 400 == 0;
}

bool cond2(int x) {
    return x % 100 == 0;
}

bool cond3(int x) {
    return x % 4 == 0;
}

int main() {
    for (int x = 0; x <= 3000; x += 100) {
        bool res = btree_eval(x, cond1, true, cond2, false, cond3, true);
        std::cout << x << ": " << res << std::endl;
    }
}
I think everything has been translated to c++98 syntax except for the variadic template (introduced in c++11) part, it is simply not possible to replicate the functionality of variadic templates in c++98.

you can now have another try!
feisty2 is offline   Reply With Quote
Old 18th June 2020, 20:03   #19  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Not really, does it work on XP ?
I mean't Does C++ work on XP not that Gobble-de-gook stuff.

C++98, CPP11, C++20, who cares, Me likee proper C, without the jibberish

EDIT:
What I know about CPP was learnt on a 6 week course about Jan 1996 [1st week instructor was off sick so 5 weeks course],
I aint really read up any further than that.
[EDIT: And I never actually used CPP at all until I joined D9 in Dec 2009, indeed I gave up all coding except for a little bit VB6, just after doing above mentioned course]
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 18th June 2020 at 23:34.
StainlessS is offline   Reply With Quote
Old 18th June 2020, 20:08   #20  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: void
Posts: 2,633
Quote:
Originally Posted by StainlessS View Post
I mean't Does C++ work on XP not that Gobble-de-gook stuff.

C++98, CPP11, C++20, who cares, Me likee proper C, without the jibberish
oh, but c is so boring, it doesn't even have templates, no, forget about parameterized polymorphism, it doesn't even have ad hoc polymorphism, and no RAII, good luck with mem leaks
feisty2 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:55.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.