Results 1 to 16 of 16

Thread: Partial function in VB6?

  1. #1

    Thread Starter
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Question Partial function in VB6?

    I wonder if partial function is possible with VB6 or not. The following code is the C# version, I've already created a working Python and C++ version but I would want to do it in VB6 also if it is possible.

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    
    class PartialFunctionApplication
    {
        static Func<T1, TResult> PartiallyApply<T1, T2, TResult>(Func<T1, T2, TResult> function, T2 argument2)
        {
            return argument1 => function(argument1, argument2);
        }
    
        static void Main()
        {
            var fs = (Func<IEnumerable<int>, Func<int, int>, IEnumerable<int>>)Enumerable.Select;
            var f1 = (Func<int, int>)(n => n * 2);
            var f2 = (Func<int, int>)(n => n * n);
            var fsf1 = PartiallyApply(fs, f1);
            var fsf2 = PartiallyApply(fs, f2);
    
            var s = new[] { 0, 1, 2, 3 };
            Console.WriteLine(string.Join(", ", fsf1(s)));
            Console.WriteLine(string.Join(", ", fsf2(s)));
    
            s = new[] { 2, 4, 6, 8 };
            Console.WriteLine(string.Join(", ", fsf1(s)));
            Console.WriteLine(string.Join(", ", fsf2(s)));
        }
    }
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: Partial function in VB6?

    You had me very confused at first as I was thinking "partial methods" and thought that this had nothing to do with that. It does indeed have nothing to do with that, because you're talking about something else entirely. Order restored.

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,543

    Re: Partial function in VB6?

    That looks like generics to me... not partial... which is a completely different thing. Also I don't think you can have partial functions/methods - in any language - partial classes, sure. Methods, no. It wouldn't make sense. Generics though... sure that makes sense. Whether VB6 can do it or not... shrug. I honestly don't know. Never thought about it.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Re: Partial function in VB6?

    Quote Originally Posted by techgnome View Post
    That looks like generics to me... not partial... which is a completely different thing. Also I don't think you can have partial functions/methods - in any language - partial classes, sure. Methods, no. It wouldn't make sense. Generics though... sure that makes sense. Whether VB6 can do it or not... shrug. I honestly don't know. Never thought about it.

    -tg
    Here's an article about partial functions in python:

    https://www.udacity.com/blog/2020/12...in-python.html
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: Partial function in VB6?

    Quote Originally Posted by techgnome View Post
    That looks like generics to me... not partial... which is a completely different thing. Also I don't think you can have partial functions/methods - in any language - partial classes, sure. Methods, no. It wouldn't make sense. Generics though... sure that makes sense. Whether VB6 can do it or not... shrug. I honestly don't know. Never thought about it.

    -tg
    I think that you made the same misinterpretation that I did initially. This is nothing to do with partial classes and partial methods. This is a functional programming concept.

  6. #6
    Hyperactive Member
    Join Date
    Jan 2018
    Posts
    268

    Re: Partial function in VB6?

    Even getting VB to call a function pointer at all takes some hacks, let alone using it generically.
    The closest you could get would be doing everything totally late-bound, with CallByName.

  7. #7
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,259

    Re: Partial function in VB6?

    Quote Originally Posted by dee-u View Post
    Here's an article about partial functions in python:

    https://www.udacity.com/blog/2020/12...in-python.html
    Here's the python-example expressed in VB6/VBA-code:
    Function-def of the "large function" (Pythonstyle)
    Code:
    Function multiply(x, y)
             multiply = x * y: End Function
    Function-def of a "manually derived" partial-function (using named parameters, to rule-out mistakes):
    Code:
    Function times_12(y)
             times_12 = multiply(x:=12, y:=y): End Function
    TestCode:
    Code:
    Sub Main()
      Debug.Print multiply(6, 7) '42
      Debug.Print times_12(2)    '24
    End Sub

    HTH

    Olaf

  8. #8
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,910

    Re: Partial function in VB6?

    I must be missing something fundamental, because I don't see a new paradigm in this..

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: Partial function in VB6?

    Quote Originally Posted by Arnoutdv View Post
    I must be missing something fundamental, because I don't see a new paradigm in this..
    I'm no expert so I might be missing something but I suspect that that's because it's an attempt to implement a functional programming concept in other than a functional programming language, so it requires stuff we already use and recognise to do something we don't usually try to do. I suspect that what's going on would be clearer in F#.

  10. #10
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,259

    Re: Partial function in VB6?

    Quote Originally Posted by Arnoutdv View Post
    I must be missing something fundamental, because I don't see a new paradigm in this..
    That's probably, because there is none...

    Olaf

  11. #11
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,169

    Re: Partial function in VB6?

    To understand currying you have to have first-class functions in the language i.e. being able to assign functions to variables like Dim a As Variant : a = MyFunction is not available in VB6.

  12. #12
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Partial function in VB6?

    I'm picturing tons of bad code out there that falls apart under maintenance. It uses such "features" by stumble-bum accident and cargo-culting and it works... until later when the house of cards comes down.

    It feels like the sort of trash only a script kiddie could love. If it has any value then a distict "assign function pointer" operator should be required.

    Algol-60's "call by name" seems far more useful and less problematic and even that used to trip people up a lot. At least a lot of compilers had the option to flag its use in order to help debug misbehaving code.

  13. #13
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,259

    Re: Partial function in VB6?

    Quote Originally Posted by wqweto View Post
    To understand currying you have to have first-class functions in the language i.e. being able to assign functions to variables like Dim a As Variant : a = MyFunction is not available in VB6.
    If one really wants to go there, then "doing it the VBScript-way" is certainly feasible:
    ...by defining a Class with a single default-method in it...

    E.g. a Sum(Func)-Definition in a Class, named Sum:
    Code:
    Public Function Ret(ParamArray Args()) '<- set the Default-Attribute on this method
      Ret = Args(0) + Args(1)
    End Function
    TestCode:
    Code:
    Sub Main()
      Dim Sum As New Sum
      Debug.Print Sum(1, 2), Sum(2, 3)
    End Sub
    A simple "Currying-demo" then requires only an additional Class, named SumCurried:
    Code:
    Private f As New Sum, m
    
    Public Function Ret(Arg) '<- set the Default-Attribute on this method
      If IsEmpty(m) Then
         Set Ret = Me
         m = Arg
      Else
         Ret = f(m, Arg)
         m = Empty
      End If
    End Function
    TestCode:
    Code:
    Sub Main()
      Dim Sum As New Sum
      Debug.Print Sum(1, 2), Sum(2, 3)
    
      Dim CurriedSum As New SumCurried
      Debug.Print CurriedSum(1)(2), CurriedSum(2)(3)
    End Sub
    Olaf

  14. #14
    Banned
    Join Date
    Sep 2022
    Posts
    16

    Re: Partial function in VB6?

    Partial methods enable developers to insert custom logic into code. Typically, the code is part of a designer-generated class. Partial methods are defined in a partial class that is created by a code generator, and they are commonly used to provide notification that something has been changed. They enable the developer to specify custom behavior in response to the change.

  15. #15
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,169

    Re: Partial function in VB6?

    Quote Originally Posted by mmarkgilbert View Post
    Partial methods enable developers to insert custom logic into code. Typically, the code is part of a designer-generated class. Partial methods are defined in a partial class that is created by a code generator, and they are commonly used to provide notification that something has been changed. They enable the developer to specify custom behavior in response to the change.
    True but OP is not about partial *methods* per se. Did you read the thread?

    cheers,
    </wqw>

  16. #16
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,140

    Re: Partial function in VB6?

    Quote Originally Posted by wqweto View Post
    True but OP is not about partial *methods* per se. Did you read the thread?

    cheers,
    </wqw>
    Don't bother with this user. If you look at all of their most recent posts, they are straight copy/paste jobs of content from other websites, so I would assume this is some sort of bot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width