Comments (4)
The ubiquitous use and utility of format
is precisely why we cannot intentionally shortcut the implementation for Mojo. It needs to work the same as Python programmers expect it to eventually. However as you mentioned the standard is quite complex and given it doesn't quite align with the short term priorities for Mojo it's unlikely to be prioritized anytime soon I would bet.
I agree having trivial stand in support for now would be nice though!
from mojo.
Thanks for opening this ticket! I agree that f-strings are one of the most useful features in Python. StringLiteral
is eventually going to become non-materializable with String
as the materialization target, so I wouldn't worry too much about it in this context.
At the same time, I strongly agree with @bgreni here: eventually we must comply with the f-string semantics dictated by Python. This doesn't mean, however, that we couldn't hill climb this. I would suggest that we start with something simple, like String.format[*Ts: Stringable](*args: *Ts)
without any ability for format specification, then extend to String.format[*Ts: Stringable, *Us: Stringable](*args: *Ts, **kwargs: *Stringable)
. This would already enable some useful functionality. It might also require some compiler improvements; if we can't prioritize those, we can fall back to just String.format(*args: String, **kwargs: String)
.
Then I would start looking at implementing the builtin format
function, along with a related trait along these lines:
trait StringFormattable: # name to be bike shedded
fn __format__(self, format_spec: StringSlice) -> String: ...
fn __format__(self) -> String: ... # overload to work around some current issues with default stringslice values
Note that we already have a Formattable
trait, but it requires a slightly lower level API. We need to think about how these could compose. @ConnorGray you have been doing some work in this area, WDYT?
from mojo.
@laszlokindrat excellent, looks like a nice plan !
@bgreni π
from mojo.
Hello @laszlokindrat , i pushed a change in #2771 for the simple {0}
+ *args
π
i feel that if anybody have a better understanding on how it works with python, they could do the implementations.
This is challenging and need to be done the right way !
I observed that if we could assign to a slice, it would be easier: res[13:16] = str(args[i])
from mojo.
Related Issues (20)
- [BUG] Index out of bound with nested list literals HOT 1
- [Feature Request] Allow __getitem__ calls to use a mix of colon slices and integers
- [BUG] Program Crash on generating simple data. HOT 1
- [BUG] errors on install HOT 3
- [Feature Request] [proposal] Fast but unsafe version of atol
- [BUG] Install Issue--Infected file warning (from Intego/Virusbarrier) HOT 2
- [BUG] Install Issue: Failed to run Script (mojo format) HOT 4
- [BUG] crash when attempting to use MAC mps when wrapping PyTorch
- [BUG] Possible SIMD[DType.bool, n] tested for truth in the stdlib where n > 1 HOT 7
- [BUG] Parser crash when a overload for a trait method is added HOT 2
- [BUG] `Tensor` initialised from a list with wrong type shows weird behaviour
- [BUG] Parser crash when `moveinit` with wrong argument convention is defined while using `@value` HOT 1
- [BUG] LSP & Mojo crashes when using Python.evaluate in a certain way HOT 4
- [Feature Request] [stdlib] [proposal] Add comp time `SIMD` range constructor
- [Feature Request] [stdlib] Add `assert_aborts()` HOT 2
- BeΔenilen HOT 1
- [Modular CLI] Include mojo version in Max --version HOT 1
- [BUG] Error output when using AOT mode but not JIT mode to run `llama3.mojo` HOT 1
- [BUG] Error output when using AOT mode but not JIT mode to run llama3.mojo
- [BUG] Error output when using AOT mode but not JIT mode to run `llama3.mojo`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mojo.