Author Topic: The V Programming Language  (Read 3274 times)

Offline AIR

  • BASIC Developer
  • Posts: 932
  • Coder
The V Programming Language
« on: March 26, 2019, 09:03:48 PM »
This isn't released yet, but it sounds promising, it will include cross platform GUI using NATIVE capability of the OS.

https://vlang.io/docs

Offline jalih

  • Advocate
  • Posts: 111
Re: The V Programming Language
« Reply #1 on: March 30, 2019, 12:51:41 AM »
Interesting...

Here is the 8th version of the sample program used in language comparison.

I got rid of the mutex guarded ids access inside the tasks and pass each task it's own slice of work. Fastest way to lock is not to lock. I also discovered a bug in 8th's current "tlshello" implementation. It currently won't play nice if used concurrently and it's access should be guarded with a lock. Bug report is filed!  ;D

Code: [Select]

needs net/http


var ids
[] var, tasks


\ Locker words. Locked variable is embedded into word, so wastes no dictionary space on captive locker variable.
"" dup
: lock-write literal lock drop ;
: unlock-write literal unlock drop ;


: STORIES_URL   "https://hacker-news.firebaseio.com/v0/topstories.json" ;
: ITEM_URL_BASE "https://hacker-news.firebaseio.com/v0/item/" ;


: get-ids
  STORIES_URL net:get if
    nip json>
    ' >s a:map ids !
  else
    "Error retrieving data." throw
  then ;


: task  \ ids-slice --
  ( nip ITEM_URL_BASE "%s%s.json" s:strfmt net:get if
      nip json>
      "title" m:@ nip
      lock-write . cr unlock-write
    else
      "Error retrieving data." throw
    then
  ) a:each drop ;


: start-tasks
  tasks @
  ( ids @ swap -1 8 a:slice+ 1 ' task t:task-n a:push  ) 0 7 loop
  drop ;


: wait-tasks
  tasks @ t:wait ;


: app:main
  get-ids
  start-tasks
  wait-tasks
  bye ;
« Last Edit: March 30, 2019, 01:17:58 AM by jalih »

Offline AIR

  • BASIC Developer
  • Posts: 932
  • Coder
Re: The V Programming Language
« Reply #2 on: August 08, 2022, 05:41:40 PM »
More than 3 years later.....

I wanted to see how hard it would be to parse the Invoice.json that John is working with in the SB Json thread.

Code: Go
  1. import x.json2
  2. import os
  3. import strings
  4.  
  5. fn spaces (num int)string {
  6.     return strings.repeat(32,num)
  7. }
  8.  
  9. fn convert(items map[string]json2.Any, num int) {
  10.     indent := spaces(num)
  11.     for name, value in items {
  12.         value_type := typeof(value)
  13.        
  14.         match value_type {
  15.             "map[string]x.json2.Any", "[]x.json2.Any" {
  16.                 println("$indent$name:")
  17.                 convert(value.as_map(), indent.len + 4)
  18.             }
  19.            
  20.             else {
  21.                 println("$indent$name: $value")
  22.             }
  23.         }
  24.     }
  25. }
  26.  
  27. fn main() {
  28.  
  29.     json_data := os.read_file('invoice.json') or {panic(err) }
  30.     result := json2.raw_decode(json_data) ?
  31.     data := result.as_map()
  32.  
  33.     for key, _ in data {
  34.         println('$key:')
  35.         obj := data['$key'] or { panic('key not found') }
  36.         items := obj.as_map()
  37.         convert(items,4)
  38.     }
  39. }
  40.  

Output:

Code: [Select]
Invoice:
    AllowIPNPayment: false
    AllowOnlinePayment: false
    AllowOnlineCreditCardPayment: false
    AllowOnlineACHPayment: false
    InvoiceLink: https://developer.intuit.com/comingSoonview/scs-v1-6330de5b6ed04fc7af182508019d19da02ecbae268eb4711bc3dd263db257d380e094b948c3f4250b5a8082dd9c333d3?locale=en_US&cta=v3invoicelink
    domain: QBO
    sparse: false
    Id: 130
    SyncToken: 0
    MetaData:
        CreateTime: 2022-06-15T13:16:17-07:00
        LastModifiedByRef:
            value: 9130354319489646
        LastUpdatedTime: 2022-06-15T13:16:17-07:00
    CustomField:
        0:
            DefinitionId: 1
            Name: Crew #
            Type: StringType
            StringValue: 102
    DocNumber: 1037
    TxnDate: 2022-06-15
    CurrencyRef:
        value: USD
        name: United States Dollar
    LinkedTxn:
        0:
            TxnId: 100
            TxnType: Estimate
    Line:
        0:
            Id: 1
            LineNum: 1
            Description: Rock Fountain
            Amount: 275
            LinkedTxn:
                0:
                    TxnId: 100
                    TxnType: Estimate
            DetailType: SalesItemLineDetail
            SalesItemLineDetail:
                ItemRef:
                    value: 5
                    name: Design:Fountains:Rock Fountain
                UnitPrice: 275
                Qty: 1
                ItemAccountRef:
                    value: 79
                    name: Sales of Product Income
                TaxCodeRef:
                    value: TAX
        1:
            Id: 2
            LineNum: 2
            Description: Fountain Pump
            Amount: 12.75
            LinkedTxn:
                0:
                    TxnId: 100
                    TxnType: Estimate
            DetailType: SalesItemLineDetail
            SalesItemLineDetail:
                ItemRef:
                    value: 11
                    name: Design:Fountains:Pump
                UnitPrice: 12.75
                Qty: 1
                ItemAccountRef:
                    value: 79
                    name: Sales of Product Income
                TaxCodeRef:
                    value: TAX
        2:
            Id: 3
            LineNum: 3
            Description: Concrete for fountain installation
            Amount: 47.5
            LinkedTxn:
                0:
                    TxnId: 100
                    TxnType: Estimate
            DetailType: SalesItemLineDetail
            SalesItemLineDetail:
                ItemRef:
                    value: 3
                    name: Design:Fountains:Concrete
                UnitPrice: 9.5
                Qty: 5
                ItemAccountRef:
                    value: 48
                    name: Landscaping Services:Job Materials:Fountains and Garden Lighting
                TaxCodeRef:
                    value: TAX
        3:
            Amount: 335.25
            DetailType: SubTotalLineDetail
            SubTotalLineDetail:
    TxnTaxDetail:
        TxnTaxCodeRef:
            value: 2
        TotalTax: 26.82
        TaxLine:
            0:
                Amount: 26.82
                DetailType: TaxLineDetail
                TaxLineDetail:
                    TaxRateRef:
                        value: 3
                    PercentBased: true
                    TaxPercent: 8
                    NetAmountTaxable: 335.25
    CustomerRef:
        value: 24
        name: Sonnenschein Family Store
    CustomerMemo:
        value: Thank you for your business and have a great day!
    BillAddr:
        Id: 95
        Line1: Russ Sonnenschein
        Line2: Sonnenschein Family Store
        Line3: 5647 Cypress Hill Ave.
        Line4: Middlefield, CA  94303
        Lat: 37.4238562
        Long: -122.1141681
    ShipAddr:
        Id: 25
        Line1: 5647 Cypress Hill Ave.
        City: Middlefield
        CountrySubDivisionCode: CA
        PostalCode: 94303
        Lat: 37.4238562
        Long: -122.1141681
    FreeFormAddress: true
    SalesTermRef:
        value: 3
        name: Net 30
    DueDate: 2022-07-15
    TotalAmt: 362.07
    ApplyTaxAfterDiscount: false
    PrintStatus: NeedToPrint
    EmailStatus: NotSet
    BillEmail:
        Address: Familiystore@intuit.com
    Balance: 362.07
time:
    0: 2022-08-06T13:48:19.168-07:00

Not hard at all.

AIR.

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: The V Programming Language
« Reply #3 on: August 08, 2022, 06:45:30 PM »
GO AIR!

That looks interesting.