Giter Club home page Giter Club logo

elvis's People

Contributors

geekrelief avatar mattaylor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

elvis's Issues

try/catch doesn't work with C interop and structs

I've been working with a C library, and the try/catch mechanism doesn't work well for digging into structs.

For example, I call function that returns a ptr.

  let draw: ptr tm_creation_graph_draw_call_data_t = render_component_api.draw_call(...)

  if ?draw.shader: 
    # do stuff

If draw is nil then I'll get a crash because the access violation is coming from C and not from Nim. My work around is to use my conditional access macro that does checks at each step.

  if ?draw.?shader:
    # do stuff

Support conditional access for function calls with args

Current conditional access templates fail to compile when matching function chains with extra args
The following fail to compile...

let tab = { "one": "uno" }.toTable
check(tab.?getOrDefault("one") == "uno") 
check(tab.?getOrDefault("two") == "")
check(tab.?getOrDefault("two", "unknown") == "unknown")

Conditional access operator with non-proc

I'm doing interop with C, and I have lots of structures that have pointer values. I want to use a conditional access operator in combination with a truthy operator like this:

  if ?data?.shader:
    # use the data.shader

But the current implementation expects shader to be a proc. Should I create a new operator for my use case or do you think ?. could be modified to handle this?

Treats an out of bounds access for an object sequence as truthy

Not quite sure what is going on, but I do have a minimal reproducible example:

import elvis

var a: seq[int] = @[]
echo ?(a[0])

type Story* = object
var stories: seq[Story]
echo ?(stories[0])

This prints

false
true

which is pretty counter intuitive, as I'd expect the second echo to print false as well.

`truthy` on nillable types does not produce the correct results

https://play.nim-lang.org/#ix=3MaY

template truthy*[T](val: T): bool = not compiles(val.isNil())

The implementation uses compile: https://nim-lang.github.io/Nim/system.html#compiles%2Cuntyped, which always returns true if val is a nillable type, but we want to actually check not val.isNil at runtime.

This will produce the expected results for nillable types.

# true if not isNil()
template truthy*[T](val: ref T): bool = not val.isNil
template truthy*[T](val: ptr T): bool = not val.isNil
template truthy*(val: pointer): bool = not val.isNil

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.