Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 00:00
    douglascamata closed #12820
  • Dec 03 23:10
    Blacksmoke16 closed #12821
  • Dec 03 23:10
    Blacksmoke16 labeled #12821
  • Dec 03 23:09
    Blacksmoke16 labeled #12821
  • Dec 03 22:13
    hutou labeled #12821
  • Dec 03 22:13
    hutou opened #12821
  • Dec 03 22:01
    douglascamata edited #12820
  • Dec 03 22:01
    douglascamata edited #12820
  • Dec 03 22:00
    douglascamata labeled #12820
  • Dec 03 22:00
    douglascamata opened #12820
  • Dec 03 19:38
    Blacksmoke16 labeled #12819
  • Dec 03 19:38
    Blacksmoke16 labeled #12819
  • Dec 03 19:16
    henrikac synchronize #12819
  • Dec 03 18:56
    henrikac opened #12819
  • Dec 03 15:33
    straight-shoota review_requested #11647
  • Dec 03 12:57
    HertzDevil edited #12818
  • Dec 03 12:54
    HertzDevil labeled #12818
  • Dec 03 12:54
    HertzDevil opened #12818
  • Dec 03 12:54
    HertzDevil labeled #12818
  • Dec 02 22:36
    straight-shoota synchronize #12809
Jason Waldrip
@jwaldrip
or, let me ask a question... do you expect your method to always return something?
Or are you just trying to invoke a method that may just invoke something, not nessicarily return something?
Ghost
@ghost~55586c4815522ed4b3e08557
@ansarizafar do you need the return value when calling it?
Zafar Ansari
@ansarizafar
yes, It could be a NameTuple or an Array Of NamedTuples
Jason Waldrip
@jwaldrip
So use a union
Zafar Ansari
@ansarizafar
Yes I need return value
Jason Waldrip
@jwaldrip
If you know the various return types, just set it up as a union
Zafar Ansari
@ansarizafar
Return types are not known in advance. Namedtuple will be generated with the fields returned from Postgre Db depending on the query.
Will
@Willamin
Hi everyone! I've got an absolutely crazy question for you. I want to reopen the Integer structs and add a macro def that throws a compile time exception based on the value of the Integer. I can't find a definitive list of macro variables such as @type and @def. Can anyone here help?
Ghost
@ghost~55586c4815522ed4b3e08557
throw a compile time error when doing what @Willamin ?
Will
@Willamin
Contrived example: I'd like to add a .is_this_a_0_at_compile_time to Integers that throws a compile time error if it's called on a non-zero integer
0.is_this_a_0_at_compile_time # should compile fine
1.is_this_a_0_at_compile_time # should throw a compile time error
Ghost
@ghost~55586c4815522ed4b3e08557
how is this supposed to be used?
Zafar Ansari
@ansarizafar
Here is my current code
module WebWare
  abstract class Method
    abstract def call(args)
  end

  class Api
    @@store = {} of String => Method

    def initialize
    end
    def self.register(name : String, method : Method)
      @@store[name] = method
    end

    def self.run(context : HTTP::Server::Context)
      begin
        data = Tools.json_param(context)
        finalResult = data.map do |key, value|
          {key => @@store[key].call(value.as(Hash))}
        end

        return finalResult.to_json
      rescue ex
        # context.response.respond_with_error("Internal error", 500)
        "Internal error in Method"
      end
    end
  end
end
Ghost
@ghost~55586c4815522ed4b3e08557
The syntax you ask is not possible because macros are not methods with a receiver, they're on the class/module/top level, not instance level, but you could have is_this_a_0_at_compile_time(0) quite easily @Willamin
Zafar Ansari
@ansarizafar
Here is User class
include WebWare

class Users < Method
  def call(args)
    begin
      count = Db.scalar "select count(*) from restock.users"
      data = [] of {id: String, name: String}

      Db.query "select id, name from restock.users" do |rs|
        rs.each do
          id, name = rs.read(String, String)
          data << {id: id, name: name}
        end
      end

      {success: true, data: data}
    rescue ex
      {success: false, data: [] of {id: String, name: String}}
    end
  end
end

Api.register "user.list", Users.new
Will
@Willamin
@bew even when it's a macro on a literal struct like an Int32?
From IRC (bridge bot)
@FromIRC
<oprypin> @eliasjpr, do u have rights to sell Crystal logo?
Ghost
@ghost~55586c4815522ed4b3e08557
yes, if you write a macro my_macro in Int32's struct, you'll be able to call it as Int32.my_macro or just my_macro when called in the scope of the Int32 struct
From IRC (bridge bot)
@FromIRC
<Papierkorb> William, how should the program know at compile-time, which run-time value the integer will have?
<Papierkorb> Crystal isn't a time machine
Ghost
@ghost~55586c4815522ed4b3e08557
\o/
Will
@Willamin
hahaha
From IRC (bridge bot)
@FromIRC
<Papierkorb> A method that takes an integer (or anything) as argument doesn't know if it was passed in as literal or through an variable (or ...), if that's what you mean.
Will
@Willamin
I was hoping that I would also be able to tell if the macro was called from a literal (eg. 0.is_this_a_0_at_compile_time) vs called from a variable (eg. x.is_this_a_0_at_compile_time),
From IRC (bridge bot)
@FromIRC
<Papierkorb> No, as a macro is state-less, you can't call it like a member method.
Ghost
@ghost~55586c4815522ed4b3e08557
Will
@Willamin
You can call a macro like a member method, using macro def, can you not?
From IRC (bridge bot)
@FromIRC
<Papierkorb> But a macro, if you pass it as argument to it, can know if it's a literal or not, and then could signal an error to the user
Ghost
@ghost~55586c4815522ed4b3e08557
@Willamin macro def is not really documented iirc, it's not meant for this use I think
From IRC (bridge bot)
@FromIRC
<Papierkorb> With a disclaimer
Ghost
@ghost~55586c4815522ed4b3e08557
ah thanks
either way, in a macro def you have access to @type (Int32) but not self (0) at compile time
Will
@Willamin
Oh well, thanks anyways! :D
Serdar Dogruyol - Sedo セド
@sdogruyol
how can I check if a value is truthy outside of a guard clause
From IRC (bridge bot)
@FromIRC
<Yxhuvud> What do you want to achieve?
Elias Perez
@eliasjpr
@oprypin My apologies was never my intention I will remove
I just wanted some tees
Elias Perez
@eliasjpr
@oprypin removed!
José Rodrigues
@joselfr
What is the LICENSE of the crystal logo?
From IRC (bridge bot)
@FromIRC
<oprypin> @eliasjpr, hey it's not my decision either way. but you're supposed to ask permission. see https://crystal-lang.org/media/ bottom of page
Elias Perez
@eliasjpr
👌🏻👍🏻 thanks
From IRC (bridge bot)
@FromIRC
<oprypin> @jose-rodrigues, see that link too
Elias Perez
@eliasjpr
I think crystal team should open a store for tees and stuff that would be a nice way to contribute for the crystal cause
From IRC (bridge bot)
@FromIRC
<oprypin> for sure
Claudio Holanda
@kazzkiq
Is Process.run a blocking method?
If I run a cURL command via Proccess.run, and it takes 10 seconds to return, is my application going to hang for 10 seconds?
From IRC (bridge bot)
@FromIRC
<oprypin> @kazzkiq, it's a convenience method that wraps Process.new and Process.wait which blocks the current fiber until the process ends
<oprypin> also why run a curl command......